MCPcopy Create free account
hub / github.com/dank/rlapi / GetExchangeCode

Method GetExchangeCode

egs.go:151–183  ·  view source on GitHub ↗

GetExchangeCode converts an EGS access token into an exchange code for EOS

(accessToken string)

Source from the content-addressed store, hash-verified

149
150// GetExchangeCode converts an EGS access token into an exchange code for EOS
151func (e *EGS) GetExchangeCode(accessToken string) (string, error) {
152 req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/account/api/oauth/exchange", egsOAuthURL), nil)
153 if err != nil {
154 return "", fmt.Errorf("failed to create request: %w", err)
155 }
156
157 req.Header.Set("Authorization", "bearer "+accessToken)
158 req.Header.Set("User-Agent", egsUserAgent)
159
160 resp, err := e.client.Do(req)
161 if err != nil {
162 return "", fmt.Errorf("failed to send request: %w", err)
163 }
164 defer resp.Body.Close()
165
166 body, err := io.ReadAll(resp.Body)
167 if err != nil {
168 return "", fmt.Errorf("failed to read response: %w", err)
169 }
170
171 if resp.StatusCode != http.StatusOK {
172 return "", fmt.Errorf("unexpected status code %s: %s", resp.Status, string(body))
173 }
174
175 var tokenResp struct {
176 Code string `json:"code"`
177 }
178 if err := json.Unmarshal(body, &tokenResp); err != nil {
179 return "", fmt.Errorf("failed to parse response: %w", err)
180 }
181
182 return tokenResp.Code, nil
183}
184
185// ExchangeEOSToken exchanges an exchange code for an EOS authentication token
186func (e *EGS) ExchangeEOSToken(exchangeCode string) (*EOSTokenResponse, error) {

Callers 2

mainFunction · 0.95
RPCFunction · 0.95

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected