split oauth_tokens.claims column up; improved fonts; allow multiple sse connections per user; make navbar and use friendly
This commit is contained in:
@@ -2,7 +2,6 @@ package authentication
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@@ -131,8 +130,6 @@ func (a *Authenticator) Exchange(ctx context.Context, state, code string) (acces
|
||||
return "", "", time.Time{}, err
|
||||
}
|
||||
|
||||
claimsJSON, _ := json.Marshal(claims)
|
||||
|
||||
// store the token, and the potentially new user
|
||||
|
||||
if _, err := a.db.Exec(
|
||||
@@ -171,7 +168,12 @@ func (a *Authenticator) Exchange(ctx context.Context, state, code string) (acces
|
||||
id_token_nonce,
|
||||
id_token_access_token_hash,
|
||||
|
||||
claims -- might want to open this up
|
||||
id_token_custom_claims_family_name,
|
||||
id_token_custom_claims_given_name,
|
||||
id_token_custom_claims_name,
|
||||
id_token_custom_claims_nickname,
|
||||
id_token_custom_claims_picture,
|
||||
id_token_custom_claims_updated_at
|
||||
)
|
||||
SELECT
|
||||
@access_token,
|
||||
@@ -187,7 +189,12 @@ func (a *Authenticator) Exchange(ctx context.Context, state, code string) (acces
|
||||
@id_token_nonce,
|
||||
@id_token_access_token_hash,
|
||||
|
||||
@claims
|
||||
@id_token_custom_claims_family_name,
|
||||
@id_token_custom_claims_given_name,
|
||||
@id_token_custom_claims_name,
|
||||
@id_token_custom_claims_nickname,
|
||||
@id_token_custom_claims_picture,
|
||||
@id_token_custom_claims_updated_at
|
||||
FROM
|
||||
the_user
|
||||
`,
|
||||
@@ -205,7 +212,12 @@ func (a *Authenticator) Exchange(ctx context.Context, state, code string) (acces
|
||||
"id_token_nonce": idToken.Nonce,
|
||||
"id_token_access_token_hash": idToken.AccessTokenHash,
|
||||
|
||||
"claims": json.RawMessage(claimsJSON),
|
||||
"id_token_custom_claims_family_name": claims.FamilyName,
|
||||
"id_token_custom_claims_given_name": claims.GivenName,
|
||||
"id_token_custom_claims_name": claims.Name,
|
||||
"id_token_custom_claims_nickname": claims.Nickname,
|
||||
"id_token_custom_claims_picture": claims.Picture,
|
||||
"id_token_custom_claims_updated_at": claims.UpdatedAt,
|
||||
},
|
||||
); err != nil {
|
||||
return "", "", time.Time{}, fmt.Errorf("failed to perform query to save tokens: %w", err)
|
||||
@@ -291,8 +303,6 @@ func (a *Authenticator) RefreshAccessToken(
|
||||
return "", time.Time{}, err
|
||||
}
|
||||
|
||||
claimsJSON, _ := json.Marshal(claims)
|
||||
|
||||
if _, err = a.db.Exec(
|
||||
ctx,
|
||||
`
|
||||
@@ -318,7 +328,12 @@ func (a *Authenticator) RefreshAccessToken(
|
||||
id_token_nonce,
|
||||
id_token_access_token_hash,
|
||||
|
||||
claims -- might want to open this up
|
||||
id_token_custom_claims_family_name,
|
||||
id_token_custom_claims_given_name,
|
||||
id_token_custom_claims_name,
|
||||
id_token_custom_claims_nickname,
|
||||
id_token_custom_claims_picture,
|
||||
id_token_custom_claims_updated_at
|
||||
)
|
||||
VALUES (
|
||||
@new_access_token,
|
||||
@@ -334,7 +349,12 @@ func (a *Authenticator) RefreshAccessToken(
|
||||
@id_token_nonce,
|
||||
@id_token_access_token_hash,
|
||||
|
||||
@claims
|
||||
@id_token_custom_claims_family_name,
|
||||
@id_token_custom_claims_given_name,
|
||||
@id_token_custom_claims_name,
|
||||
@id_token_custom_claims_nickname,
|
||||
@id_token_custom_claims_picture,
|
||||
@id_token_custom_claims_updated_at
|
||||
)
|
||||
RETURNING
|
||||
access_token AS new_access_token
|
||||
@@ -363,7 +383,12 @@ func (a *Authenticator) RefreshAccessToken(
|
||||
"id_token_nonce": idToken.Nonce,
|
||||
"id_token_access_token_hash": idToken.AccessTokenHash,
|
||||
|
||||
"claims": json.RawMessage(claimsJSON),
|
||||
"id_token_custom_claims_family_name": claims.FamilyName,
|
||||
"id_token_custom_claims_given_name": claims.GivenName,
|
||||
"id_token_custom_claims_name": claims.Name,
|
||||
"id_token_custom_claims_nickname": claims.Nickname,
|
||||
"id_token_custom_claims_picture": claims.Picture,
|
||||
"id_token_custom_claims_updated_at": claims.UpdatedAt,
|
||||
},
|
||||
); err != nil {
|
||||
return "", time.Time{}, fmt.Errorf("failed to save new access token and delete old access token: %w", err)
|
||||
@@ -372,12 +397,14 @@ func (a *Authenticator) RefreshAccessToken(
|
||||
return tkn.AccessToken, tkn.Expiry.UTC(), nil
|
||||
}
|
||||
|
||||
func (a *Authenticator) verifyIDTokenAndClaimsFromToken(ctx context.Context, tkn *oauth2.Token) (idToken *oidc.IDToken, claims map[string]any, err error) {
|
||||
func (a *Authenticator) verifyIDTokenAndClaimsFromToken(ctx context.Context, tkn *oauth2.Token) (idToken *oidc.IDToken, claims *AccessTokenClaims, err error) {
|
||||
if idToken, err = a.VerifyIDToken(ctx, tkn); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to verify id Token: %w", err)
|
||||
}
|
||||
|
||||
if err := idToken.Claims(&claims); err != nil {
|
||||
claims = new(AccessTokenClaims)
|
||||
|
||||
if err := idToken.Claims(claims); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to obtain id token claims: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user