FetchAuthUser returns an AuthUser instance based on the Linear's user api. API reference: https://developers.linear.app/docs/graphql/working-with-the-graphql-api#authentication
(token *oauth2.Token)
| 46 | // |
| 47 | // API reference: https://developers.linear.app/docs/graphql/working-with-the-graphql-api#authentication |
| 48 | func (p *Linear) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { |
| 49 | data, err := p.FetchRawUserInfo(token) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | rawUser := map[string]any{} |
| 55 | if err := json.Unmarshal(data, &rawUser); err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | extracted := struct { |
| 60 | Data struct { |
| 61 | Viewer struct { |
| 62 | Id string `json:"id"` |
| 63 | DisplayName string `json:"displayName"` |
| 64 | Name string `json:"name"` |
| 65 | Email string `json:"email"` |
| 66 | AvatarURL string `json:"avatarUrl"` |
| 67 | Active bool `json:"active"` |
| 68 | } `json:"viewer"` |
| 69 | } `json:"data"` |
| 70 | }{} |
| 71 | |
| 72 | if err := json.Unmarshal(data, &extracted); err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | |
| 76 | if !extracted.Data.Viewer.Active { |
| 77 | return nil, errors.New("the Linear user account is not active") |
| 78 | } |
| 79 | |
| 80 | user := &AuthUser{ |
| 81 | Id: extracted.Data.Viewer.Id, |
| 82 | Name: extracted.Data.Viewer.Name, |
| 83 | Username: extracted.Data.Viewer.DisplayName, |
| 84 | Email: extracted.Data.Viewer.Email, |
| 85 | AvatarURL: extracted.Data.Viewer.AvatarURL, |
| 86 | RawUser: rawUser, |
| 87 | AccessToken: token.AccessToken, |
| 88 | RefreshToken: token.RefreshToken, |
| 89 | } |
| 90 | |
| 91 | user.Expiry, _ = types.ParseDateTime(token.Expiry) |
| 92 | |
| 93 | return user, nil |
| 94 | } |
| 95 | |
| 96 | // FetchRawUserInfo implements Provider.FetchRawUserInfo interface method. |
| 97 | // |
nothing calls this directly
no test coverage detected