Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
need to special case the callback logic too (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
wild-endeavor authored Feb 4, 2020
1 parent f23975c commit 787edbc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/auth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func GetLoginHandler(ctx context.Context, authContext interfaces.AuthenticationC
}

func GetCallbackHandler(ctx context.Context, authContext interfaces.AuthenticationContext) http.HandlerFunc {
l5OauthConfig := GetL5Oauth2Config(authContext.OAuth2Config())
return func(writer http.ResponseWriter, request *http.Request) {
logger.Debugf(ctx, "Running callback handler...")
authorizationCode := request.FormValue(AuthorizationResponseCodeType)
Expand All @@ -114,11 +115,22 @@ func GetCallbackHandler(ctx context.Context, authContext interfaces.Authenticati
// The second parameter is necessary to get the initial refresh token
offlineAccessParam := oauth2.SetAuthURLParam(RefreshToken, OfflineAccessType)

token, err := authContext.OAuth2Config().Exchange(ctx, authorizationCode, offlineAccessParam)
if err != nil {
logger.Errorf(ctx, "Error when exchanging code %s", err)
writer.WriteHeader(http.StatusForbidden)
return
var token *oauth2.Token
// Additional hacks for L5
if strings.Contains(request.Host, "flyte-rs.av.lyft.net") {
token, err = l5OauthConfig.Exchange(ctx, authorizationCode, offlineAccessParam)
if err != nil {
logger.Errorf(ctx, "Error when exchanging code %s", err)
writer.WriteHeader(http.StatusForbidden)
return
}
} else {
token, err = authContext.OAuth2Config().Exchange(ctx, authorizationCode, offlineAccessParam)
if err != nil {
logger.Errorf(ctx, "Error when exchanging code %s", err)
writer.WriteHeader(http.StatusForbidden)
return
}
}

err = authContext.CookieManager().SetTokenCookies(ctx, writer, token)
Expand Down

0 comments on commit 787edbc

Please sign in to comment.