func (r *Repo) Auth(ctx context.Context, provider, token string) error {
	auth := auth.NewOAuth2(provider, token)
	if err := r.chttp.Auth(ctx, auth); err != nil {
		return errors.Wrap(err, "OAuth2 auth failed")
	}
	var response struct {
		Ctx struct {
			Name string `json:"name"`
		} `json:"userCtx"`
	}
	if _, err := r.chttp.DoJSON(ctx, http.MethodGet, "/_session", nil, &response); err != nil {
		return errors.Wrap(err, "failed to validate session")
	}
	if response.Ctx.Name == "" {
		return errors.New("no user set in session")
	}
	return r.setUser(ctx, response.Ctx.Name)
}
// Auth attempts to authenticate with the provided OAuth2 provider/token pair.
Auth attempts to authenticate with the provided OAuth2 provider/token pair.
// Auth attempts to authenticate with the provided OAuth2 provider / token pair .
func (r *Repo) Auth(ctx context.Context, provider, token string) error {
	auth := auth.NewOAuth2(provider, token)
	if err := r.chttp.Auth(ctx, auth); err != nil {
		return errors.Wrap(err, "OAuth2 auth failed")
	}
	var response struct {
		Ctx struct {
			Name string `json:"name"`
		} `json:"userCtx"`
	}
	if _, err := r.chttp.DoJSON(ctx, http.MethodGet, "/_session", nil, &response); err != nil {
		return errors.Wrap(err, "failed to validate session")
	}
	if response.Ctx.Name == "" {
		return errors.New("no user set in session")
	}
	return r.setUser(ctx, response.Ctx.Name)
}
func ( r * Repo ) Auth ( ctx context . Context , provider , token string ) error { auth := auth . NewOAuth2 ( provider , token ) if err := r . chttp . Auth ( ctx , auth ) ; err != nil { return errors . Wrap ( err , " " ) } var response struct { Ctx struct { Name string `json:"name"` } `json:"userCtx"` } if _ , err := r . chttp . DoJSON ( ctx , http . MethodGet , " " , nil , & response ) ; err != nil { return errors . Wrap ( err , " " ) } if response . Ctx . Name == " " { return errors . New ( " " ) } return r . setUser ( ctx , response . Ctx . Name ) }
Auth attempts to authenticate with the provided OAuth2 provider/token pair.
Auth attempts to authenticate with the provided OAuth2 provider / token pair .