Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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