Skip to content

Commit

Permalink
feat: get the logged in user info
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Jan 12, 2023
1 parent 400d25a commit 285e8e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *Client) VerifyAccessToken(ctx context.Context, accessToken string) (*To
}

if !introspectionResponse.Active {
return nil, fmt.Errorf("the supplied access token is not valid")
return nil, fmt.Errorf("the supplied access token is invalid")
}

return introspectionResponse, nil
Expand Down
23 changes: 23 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package authutils

import (
"context"
"fmt"

"github.com/savannahghi/firebasetools"
)

// GetLoggedInUserUID returns user information as part of OIDC protocol.
func GetLoggedInUserUID(ctx context.Context) (string, error) {
val := ctx.Value(firebasetools.AuthTokenContextKey)
if val == nil {
return "", fmt.Errorf("unable to get auth token from context with key: %s", firebasetools.AuthTokenContextKey)
}

token, ok := val.(*TokenIntrospectionResponse)
if !ok {
return "", fmt.Errorf("wrong auth token type, got %v", token)
}

return token.Sub, nil
}

0 comments on commit 285e8e7

Please sign in to comment.