(ctx context.Context, accessToken string)
| 105 | } |
| 106 | |
| 107 | func (c genericOauthClient) inspectOauthAccessToken(ctx context.Context, accessToken string) (*InspectResponse, error) { |
| 108 | req, err := http.NewRequest("GET", c.InspectLocation, nil) |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | req.WithContext(ctx) |
| 113 | req.Header.Set("User-Agent", ServerUserAgent("")) |
| 114 | req.Header.Set("Accept", "application/json") |
| 115 | req.Header.Set("Authorization", "Bearer "+accessToken) |
| 116 | |
| 117 | resp, err := c.HttpClient.Do(req) |
| 118 | if err != nil { |
| 119 | return nil, err |
| 120 | } |
| 121 | if resp.StatusCode != http.StatusOK { |
| 122 | return nil, errors.New("unable to inspect access token") |
| 123 | } |
| 124 | |
| 125 | // since we don't know what the JSON from the server will look like, we create a |
| 126 | // generic interface and then map manually to values set in the config |
| 127 | var genericInterface map[string]interface{} |
| 128 | if err := limitedJsonUnmarshal(resp.Body, infoRequestMaxLen, &genericInterface); err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | |
| 132 | // map each relevant field in inspectResponse to the mapped field from the config |
| 133 | var inspectResponse InspectResponse |
| 134 | inspectResponse.UserID, _ = genericInterface[c.MapUserID].(string) |
| 135 | if inspectResponse.UserID == "" { |
| 136 | log.Error("[CONFIGURATION ERROR] Generic OAuth provider returned empty UserID value (`%s`).\n Do you need to configure a different `map_user_id` value for this provider?", c.MapUserID) |
| 137 | return nil, fmt.Errorf("no UserID (`%s`) value returned", c.MapUserID) |
| 138 | } |
| 139 | inspectResponse.Username, _ = genericInterface[c.MapUsername].(string) |
| 140 | inspectResponse.DisplayName, _ = genericInterface[c.MapDisplayName].(string) |
| 141 | inspectResponse.Email, _ = genericInterface[c.MapEmail].(string) |
| 142 | |
| 143 | return &inspectResponse, nil |
| 144 | } |
nothing calls this directly
no test coverage detected