Minor changes

This commit is contained in:
David Allen 2024-02-25 10:00:55 -07:00
parent dcfd9b5906
commit 4bfadc57bc
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
3 changed files with 9 additions and 19 deletions

View file

@ -83,7 +83,7 @@ func Login(config *Config) error {
// unmarshal data to get id_token and access_token
var data map[string]any
err = json.Unmarshal([]byte(tokenString), &data)
if err != nil {
if err != nil || data == nil {
return fmt.Errorf("failed to unmarshal token: %v", err)
}
@ -128,6 +128,7 @@ func Login(config *Config) error {
if err != nil {
return fmt.Errorf("failed to fetch identities: %v", err)
}
fmt.Printf("Created new identity successfully.\n")
}
// extract the subject from ID token claims
@ -160,13 +161,16 @@ func Login(config *Config) error {
fmt.Printf("Fetching JWKS from authentication server for verification...\n")
err = idp.FetchJwk(config.ActionUrls.JwksUri)
if err != nil {
fmt.Printf("failed to fetch JWK: %v\n", err)
return fmt.Errorf("failed to fetch JWK: %v\n", err)
} else {
fmt.Printf("Attempting to add issuer to authorization server...\n")
_, err = client.AddTrustedIssuer(config.ActionUrls.TrustedIssuers, idp, subject, time.Duration(1000), config.Scope)
res, err := client.AddTrustedIssuer(config.ActionUrls.TrustedIssuers, idp, subject, time.Duration(1000), config.Scope)
if err != nil {
return fmt.Errorf("failed to add trusted issuer: %v", err)
}
if string(res) == "" {
fmt.Printf("Added issuer to authorization server successfully.\n")
}
}
// use ID token/user info to fetch access token from authentication server