tokenHandler handles token handling performed by the OAuth Authorization Server. It mocks token response and makes it available as JSON document.
(w http.ResponseWriter, r *http.Request)
| 293 | // tokenHandler handles token handling performed by the OAuth Authorization Server. |
| 294 | // It mocks token response and makes it available as JSON document. |
| 295 | func (s *mockAuthServer) tokenHandler(w http.ResponseWriter, r *http.Request) { |
| 296 | if (s.options.forceError.errorType == callbackTokenExchangeErr && s.options.grantType == grantTypeAuthCode) || |
| 297 | (s.options.forceError.errorType == refreshTokenExchangeErr && s.options.grantType == grantTypeRefreshToken) { |
| 298 | w.WriteHeader(http.StatusUnauthorized) |
| 299 | return |
| 300 | } |
| 301 | claims := s.options.claims |
| 302 | if reflect.DeepEqual(s.options.claims, claimSet{}) { |
| 303 | claims = claimsAuthentic() |
| 304 | } |
| 305 | token, err := s.makeToken(claims) |
| 306 | if err != nil || token == "" { |
| 307 | w.WriteHeader(http.StatusUnauthorized) |
| 308 | return |
| 309 | } |
| 310 | response := OIDCTokenResponse{ |
| 311 | IDToken: token, |
| 312 | AccessToken: "7d1d234f5fde713a94454f268833adcd39835fe8", |
| 313 | RefreshToken: "e08c77351221346153d09ff64c123b24fc4c1905", |
| 314 | TokenType: BearerToken, |
| 315 | Expires: 300, // Expires in 5 minutes from when the response was generated. |
| 316 | } |
| 317 | if (s.options.grantType == grantTypeAuthCode && s.options.forceError.errorType == callbackNoIDTokenErr) || |
| 318 | (s.options.grantType == grantTypeRefreshToken && s.options.forceError.errorType == refreshNoIDTokenErr) { |
| 319 | response.IDToken = "" |
| 320 | } |
| 321 | s.options.tokenResponse = response |
| 322 | renderJSON(w, r, http.StatusOK, response) |
| 323 | } |
| 324 | |
| 325 | // claimSet represents a set of public and private claim values. |
| 326 | type claimSet struct { |
nothing calls this directly
no test coverage detected