Skip to content

Commit

Permalink
fix: flagged feature disabled on token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedykori committed Aug 17, 2021
1 parent 0e4fbd5 commit 5464178
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions pkg/onboarding/infrastructure/database/fb/firebase.go
Expand Up @@ -2154,14 +2154,48 @@ func (fr Repository) ExchangeRefreshTokenForIDToken(
))
}

var tokenResp profileutils.AuthCredentialResponse
err = json.NewDecoder(resp.Body).Decode(&tokenResp)
type refreshTokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn string `json:"expires_in"`
TokenType string `json:"token_type"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token"`
UserID string `json:"user_id"`
ProjectID string `json:"project_id"`
}

var tokenResponse refreshTokenResponse
err = json.NewDecoder(resp.Body).Decode(&tokenResponse)
if err != nil {
utils.RecordSpanError(span, err)
return nil, exceptions.InternalServerError(err)
return nil, exceptions.InternalServerError(fmt.Errorf(
"failed to decode refresh token response: %s", err,
))
}

profile, err := fr.GetUserProfileByUID(ctx, tokenResponse.UserID, false)
if err != nil {
utils.RecordSpanError(span, err)
return nil, exceptions.InternalServerError(fmt.Errorf(
"failed to retrieve user profile: %s", err,
))
}

return &tokenResp, nil
canExperiment, err := fr.CheckIfExperimentParticipant(ctx, profile.ID)
if err != nil {
utils.RecordSpanError(span, err)
return nil, exceptions.InternalServerError(fmt.Errorf(
"failed to check if the logged in user is an experimental participant: %s", err,
))
}

return &profileutils.AuthCredentialResponse{
IDToken: &tokenResponse.IDToken,
ExpiresIn: tokenResponse.ExpiresIn,
RefreshToken: tokenResponse.RefreshToken,
UID: tokenResponse.UserID,
CanExperiment: canExperiment,
}, nil
}

// GetCustomerProfileByID fetch the customer profile by profile id.
Expand Down

0 comments on commit 5464178

Please sign in to comment.