Skip to content

Commit

Permalink
fix: checking email
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 9, 2024
1 parent 75924de commit c024d1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
10 changes: 0 additions & 10 deletions adapters/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,3 @@ func (a *UnimplementedAdapter) CreateVerificationToken(_ context.Context, erfica
func (a *UnimplementedAdapter) UseVerficationToken(_ context.Context, identifier string, token string) (GothVerificationToken, error) {
return GothVerificationToken{}, ErrUnimplemented
}

// StringPtr returns a pointer to the string value passed in.
func StringPtr(s string) *string {
return &s
}

// TimePtr returns a pointer to the time value passed in.
func TimePtr(t time.Time) *time.Time {
return &t
}
17 changes: 9 additions & 8 deletions providers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/zeiss/fiber-goth/adapters"
"github.com/zeiss/fiber-goth/providers"
"github.com/zeiss/pkg/cast"
"github.com/zeiss/pkg/slices"
"github.com/zeiss/pkg/utilx"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -151,28 +152,28 @@ func (g *githubProvider) CompleteAuth(ctx context.Context, adapter adapters.Adap
user := adapters.GothUser{
Name: u.Name,
Email: u.Email,
Image: &u.Picture,
Image: cast.Ptr(u.Picture),
Accounts: []adapters.GothAccount{
{
Type: adapters.AccountTypeOAuth2,
Provider: g.ID(),
ProviderAccountID: adapters.StringPtr(strconv.Itoa(u.ID)),
AccessToken: adapters.StringPtr(token.AccessToken),
RefreshToken: adapters.StringPtr(token.RefreshToken),
ExpiresAt: adapters.TimePtr(token.Expiry),
ProviderAccountID: cast.Ptr(strconv.Itoa(u.ID)),
AccessToken: cast.Ptr(token.AccessToken),
RefreshToken: cast.Ptr(token.RefreshToken),
ExpiresAt: cast.Ptr(token.Expiry),
SessionState: token.Extra("state").(string),
},
},
}

if utilx.Empty(u.Email) && slices.Any(checkScope, g.config.Scopes...) {
u.Email, err = getPrivateMail(ctx, g, token)
if utilx.Empty(user.Email) && slices.Any(checkScope, g.config.Scopes...) {
user.Email, err = getPrivateMail(ctx, g, token)
if err != nil {
return user, err
}
}

if utilx.Empty(u.Email) {
if utilx.Empty(user.Email) {
return user, ErrNoVerifiedPrimaryEmail
}

Expand Down

0 comments on commit c024d1f

Please sign in to comment.