Repository: markbates/goth (go)

Issue:
Add EmailVerified field in Apple Session
Can we add support of new field "EmailVerified" in Apple's ID Token introduced in this thread? Some of us do refer to this field to confirm if users are verified:

https://developer.apple.com/forums/thread/121411?answerId=378290022#378290022



Pull request:
[Enhancement] Add EmailVerified field for Apple's ID token
Open issue: 

[https://github.com/markbates/goth/issues/557]

Close #557  



Patch:
diff --git a/providers/apple/session.go b/providers/apple/session.go
index 6d239c3..e80e1ba 100644
--- a/providers/apple/session.go
+++ b/providers/apple/session.go
@@ -24,6 +24,7 @@ type ID struct {
 	Sub            string `json:"sub"`
 	Email          string `json:"email"`
 	IsPrivateEmail bool   `json:"is_private_email"`
+	EmailVerified  bool   `json:"email_verified"`
 }
 
 type Session struct {
@@ -52,6 +53,7 @@ type IDTokenClaims struct {
 	AuthTime        int        `json:"auth_time"`
 	Email           string     `json:"email"`
 	IsPrivateEmail  BoolString `json:"is_private_email"`
+	EmailVerified   BoolString `json:"email_verified,omitempty"`
 }
 
 func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) {
@@ -124,6 +126,7 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string,
 			Sub:            idToken.Claims.(*IDTokenClaims).Subject,
 			Email:          idToken.Claims.(*IDTokenClaims).Email,
 			IsPrivateEmail: idToken.Claims.(*IDTokenClaims).IsPrivateEmail.Value(),
+			EmailVerified:  idToken.Claims.(*IDTokenClaims).EmailVerified.Value(),
 		}
 	}
 


Test patch:
diff --git a/providers/apple/session_test.go b/providers/apple/session_test.go
index 4516dcd..031b916 100644
--- a/providers/apple/session_test.go
+++ b/providers/apple/session_test.go
@@ -37,7 +37,7 @@ func Test_ToJSON(t *testing.T) {
 	s := &Session{}
 
 	data := s.Marshal()
-	a.Equal(data, `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"","is_private_email":false}`)
+	a.Equal(data, `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"","is_private_email":false,"email_verified":false}`)
 }
 
 func Test_String(t *testing.T) {
@@ -59,23 +59,30 @@ func TestIDTokenClaimsUnmarshal(t *testing.T) {
 	}{
 		{
 			name:    "'is_private_email' claim is a string",
-			idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"test-email@privaterelay.appleid.com","is_private_email":"true"}`,
+			idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"test-email@privaterelay.appleid.com","is_private_email":"true", "email_verified":"true"}`,
 			expectedClaims: IDTokenClaims{
 				Email: "test-email@privaterelay.appleid.com",
 				IsPrivateEmail: BoolString{
 					StringValue: "true",
 				},
+				EmailVerified: BoolString{
+					StringValue: "true",
+				},
 			},
 		},
 		{
 			name:    "'is_private_email' claim is a boolean",
-			idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"test-email@privaterelay.appleid.com","is_private_email":true}`,
+			idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"test-email@privaterelay.appleid.com","is_private_email":true,"email_verified":true}`,
 			expectedClaims: IDTokenClaims{
 				Email: "test-email@privaterelay.appleid.com",
 				IsPrivateEmail: BoolString{
 					BoolValue:   true,
 					IsValidBool: true,
 				},
+				EmailVerified: BoolString{
+					BoolValue:   true,
+					IsValidBool: true,
+				},
 			},
 		},
 	}