authHandler mocks the authentication process performed by the OAuth Authorization Server. The behavior of authHandler can be modified through the options map when needed. Clients are redirected to the specified callback URL after successful authentication.
(w http.ResponseWriter, r *http.Request)
| 249 | // The behavior of authHandler can be modified through the options map when needed. |
| 250 | // Clients are redirected to the specified callback URL after successful authentication. |
| 251 | func (s *mockAuthServer) authHandler(w http.ResponseWriter, r *http.Request) { |
| 252 | var redirectionURL string |
| 253 | state := r.URL.Query().Get(requestParamState) |
| 254 | if s.options.forceError.errorType == invalidStateErr { |
| 255 | state = "aW52YWxpZCBzdGF0ZQo=" // Invalid state to simulate CSRF |
| 256 | } |
| 257 | redirect := r.URL.Query().Get(requestParamRedirectURI) |
| 258 | if redirect == "" { |
| 259 | base.ErrorfCtx(r.Context(), "No redirect URL found in auth request") |
| 260 | w.WriteHeader(http.StatusInternalServerError) |
| 261 | return |
| 262 | } |
| 263 | if s.options.forceError.errorType == callbackErr { |
| 264 | err := "?error=unsupported_response_type&error_description=response_type%20not%20supported" |
| 265 | redirectionURL = fmt.Sprintf("%s?error=%s", redirect, err) |
| 266 | http.Redirect(w, r, redirectionURL, http.StatusTemporaryRedirect) |
| 267 | } |
| 268 | code, err := base.GenerateRandomSecret() |
| 269 | if err != nil { |
| 270 | base.ErrorfCtx(r.Context(), "%s", err.Error()) |
| 271 | w.WriteHeader(http.StatusInternalServerError) |
| 272 | return |
| 273 | } |
| 274 | if s.options.forceError.errorType == noCodeErr { |
| 275 | code = "" |
| 276 | } |
| 277 | redirectionURL = fmt.Sprintf("%s?code=%s", redirect, code) |
| 278 | if state != "" { |
| 279 | redirectionURL = fmt.Sprintf("%s&state=%s", redirectionURL, state) |
| 280 | } |
| 281 | if s.options.forceError.errorType == untoldProviderErr { |
| 282 | uri, err := auth.SetURLQueryParam(redirectionURL, requestParamProvider, "untold") |
| 283 | if err != nil { |
| 284 | base.ErrorfCtx(r.Context(), "error setting untold provider in mock callback URL") |
| 285 | w.WriteHeader(http.StatusInternalServerError) |
| 286 | return |
| 287 | } |
| 288 | redirectionURL = uri |
| 289 | } |
| 290 | http.Redirect(w, r, redirectionURL, http.StatusTemporaryRedirect) |
| 291 | } |
| 292 | |
| 293 | // tokenHandler handles token handling performed by the OAuth Authorization Server. |
| 294 | // It mocks token response and makes it available as JSON document. |
nothing calls this directly
no test coverage detected