Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var GithubUserFetcher = func(ctx context.Context, config *oauth2.Config, token *oauth2.Token) (nakama.ProvidedUser, error) { const baseURL = "https://api.github.com" var user struct { ID int `json:"id"` Login string `json:"login"` } var emails []struct { Email string `json:"email"` Primary bool `json:"primary"` Verified bool `json:"verified"` } g, gctx := errgroup.WithContext(ctx) g.Go(func() error { req, err := http.NewRequestWithContext(gctx, http.MethodGet, baseURL+"/user", nil) if err != nil { return fmt.Errorf("could not create user request: %w", err) } req.Header.Set("User-Agent", "nakama") resp, err := config.Client(ctx, token).Do(req) if err != nil { return errServiceUnavailable } defer resp.Body.Close() if resp.StatusCode >= 400 { return errServiceUnavailable } err = json.NewDecoder(resp.Body).Decode(&user) if err != nil { return errServiceUnavailable } return nil }) g.Go(func() error { req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/user/emails", nil) if err != nil { return fmt.Errorf("could not create user emails request: %w", err) } req.Header.Set("User-Agent", "nakama") resp, err := config.Client(ctx, token).Do(req) if err != nil { return errServiceUnavailable } defer resp.Body.Close() if resp.StatusCode >= 400 { return errServiceUnavailable } err = json.NewDecoder(resp.Body).Decode(&emails) if err != nil { return errServiceUnavailable } return nil }) var out nakama.ProvidedUser if err := g.Wait(); err != nil { return out, err } for _, email := range emails { if email.Email != "" && email.Verified && email.Primary { out.Email = email.Email break } } if out.Email == "" { for _, email := range emails { if email.Email != "" && email.Verified { out.Email = email.Email break } } } if out.Email == "" { return out, errEmailNotProvided } out.ID = fmt.Sprintf("%d", user.ID) out.Username = &user.Login return out, nil }
Functions ¶
func New ¶
func New(svc transport.Service, oauthProviders []OauthProvider, origin *url.URL, logger log.Logger, store storage.Store, cdc *securecookie.SecureCookie, promHandler http.Handler, embedStaticFiles bool) http.Handler
New makes use of the service to provide an http.Handler with predefined routing.
Types ¶
Click to show internal directories.
Click to hide internal directories.