Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unmarshal is_private_email correctly #1402

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion internal/api/provider/apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/url"
"strconv"
"strings"

"github.com/coreos/go-oidc/v3/oidc"
Expand All @@ -17,10 +18,36 @@ const IssuerApple = "https://appleid.apple.com"
// AppleProvider stores the custom config for apple provider
type AppleProvider struct {
*oauth2.Config

oidc *oidc.Provider
}

type IsPrivateEmail bool

// Apple returns an is_private_email field that could be a string or boolean value so we need to implement a custom unmarshaler
// https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple
func (b *IsPrivateEmail) UnmarshalJSON(data []byte) error {
var boolVal bool
if err := json.Unmarshal(data, &boolVal); err == nil {
*b = IsPrivateEmail(boolVal)
return nil
}

// ignore the error and try to unmarshal as a string
var strVal string
if err := json.Unmarshal(data, &strVal); err != nil {
return err
}

var err error
boolVal, err = strconv.ParseBool(strVal)
if err != nil {
return err
}

*b = IsPrivateEmail(boolVal)
return nil
}

type appleName struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Expand Down
4 changes: 2 additions & 2 deletions internal/api/provider/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ type AppleIDTokenClaims struct {

Email string `json:"email"`

AuthTime *float64 `json:"auth_time"`
IsPrivateEmail *bool `json:"is_private_email,string"`
AuthTime *float64 `json:"auth_time"`
IsPrivateEmail *IsPrivateEmail `json:"is_private_email"`
}

func parseAppleIDToken(token *oidc.IDToken) (*oidc.IDToken, *UserProvidedData, error) {
Expand Down
Loading