GetUserInfo provider specific call to get userinfomation
(r *http.Request, user *structs.User, customClaims *structs.CustomClaims, ptokens *structs.PTokens, opts ...oauth2.AuthCodeOption)
| 37 | |
| 38 | // GetUserInfo provider specific call to get userinfomation |
| 39 | func (Provider) GetUserInfo(r *http.Request, user *structs.User, customClaims *structs.CustomClaims, ptokens *structs.PTokens, opts ...oauth2.AuthCodeOption) (rerr error) { |
| 40 | _, _, err := common.PrepareTokensAndClient(r, ptokens, true, opts...) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | // For Azure AD, there is very little information in the /userinfo response. |
| 46 | // Since we can get everything we currently need from the access token, we are |
| 47 | // just going to extract user info and custom claims from there. |
| 48 | azureUser := structs.AzureUser{} |
| 49 | |
| 50 | var tokenParts []string |
| 51 | |
| 52 | if cfg.GenOAuth.AzureToken == "access_token" { |
| 53 | tokenParts = strings.Split(ptokens.PAccessToken, ".") |
| 54 | } else if cfg.GenOAuth.AzureToken == "id_token" { |
| 55 | tokenParts = strings.Split(ptokens.PIdToken, ".") |
| 56 | } else { |
| 57 | err = fmt.Errorf("azure Token not access_token or id_token") |
| 58 | log.Error(err) |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | if len(tokenParts) < 2 { |
| 63 | err = fmt.Errorf("azure GetUserInfo: invalid token received; not enough parts") |
| 64 | log.Error(err) |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | tokenBytes, err := base64.RawURLEncoding.DecodeString(tokenParts[1]) |
| 69 | if err != nil { |
| 70 | err = fmt.Errorf("azure GetUserInfo: decoding token failed: %+v", err) |
| 71 | log.Error(err) |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | if err = common.MapClaims(tokenBytes, customClaims); err != nil { |
| 76 | log.Error(err) |
| 77 | return err |
| 78 | } |
| 79 | |
| 80 | log.Debugf("azure GetUserInfo: getting user info from token: %+v", string(tokenBytes)) |
| 81 | if err = json.Unmarshal(tokenBytes, &azureUser); err != nil { |
| 82 | err = fmt.Errorf("azure getUserInfoFromTokens: unpacking token into AzureUser failed: %+v", err) |
| 83 | log.Error(err) |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | azureUser.PrepareUserData() |
| 88 | |
| 89 | user.Username = azureUser.Username |
| 90 | user.Name = azureUser.Name |
| 91 | user.Email = azureUser.Email |
| 92 | log.Infof("azure GetUserInfo: User: %+v", user) |
| 93 | |
| 94 | return nil |
| 95 | } |
nothing calls this directly
no test coverage detected