MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / tokenHandler

Method tokenHandler

rest/oidc_api_test.go:295–323  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

293// tokenHandler handles token handling performed by the OAuth Authorization Server.
294// It mocks token response and makes it available as JSON document.
295func (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.
326type claimSet struct {

Callers

nothing calls this directly

Calls 4

makeTokenMethod · 0.95
claimsAuthenticFunction · 0.85
renderJSONFunction · 0.85
WriteHeaderMethod · 0.45

Tested by

no test coverage detected