-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (35 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package example
import (
"context"
"errors"
"fmt"
"github.com/huydang284/apple-signin"
"io/ioutil"
"os"
)
const (
AppleSignInClientID = "com.example.app"
AppleSignInTeamID = "11AAAAA1AA"
)
func main() {
appleSignInSecretPath := os.Getenv("APPLE_SIGN_IN_SECRET_PATH")
appleSignInKeyID := os.Getenv("APPLE_SIGN_IN_KEY_ID")
if appleSignInSecretPath == "" || appleSignInKeyID == "" {
panic(errors.New("apple sign in configurations is missing"))
}
secret, err := ioutil.ReadFile(appleSignInSecretPath)
if err != nil {
panic(err)
}
clientSecret, err := apple_signin.GenerateClientSecret(secret, AppleSignInTeamID, AppleSignInClientID, appleSignInKeyID)
if err != nil {
panic(err)
}
code := "" // this code is sent from mobile app (or web) after user allowed to use Apple Signin
appleSignInClient := apple_signin.New(AppleSignInClientID, clientSecret)
tokenResponse, err := appleSignInClient.VerifyAppToken(context.TODO(), code)
if err != nil {
panic(err)
}
fmt.Println(tokenResponse.Claims.Email)
}