@@ -40,7 +40,6 @@ export interface AppleKey {
4040export class AppleAuth {
4141 private kv : KVNamespace
4242 private keyId : string
43- private clientId : string
4443 private teamId : string
4544 private privateKey : string
4645
@@ -53,7 +52,6 @@ export class AppleAuth {
5352 this . kv = env . KV
5453 this . keyId = env . APPLE_SIGN_KEY_ID
5554 this . privateKey = env . APPLE_SIGN_AUTH_KEY
56- this . clientId = env . APPLE_SIGN_CLIENT_ID
5755 this . teamId = env . APPLE_SIGN_TEAM_ID
5856 this . privateKey = this . privateKey
5957 . replace ( / \\ n / g, '' )
@@ -63,7 +61,7 @@ export class AppleAuth {
6361 }
6462
6563 // get client secret
66- private async getClientSecret ( ) : Promise < string > {
64+ private async getClientSecret ( clientId : string ) : Promise < string > {
6765 const header = { alg : AppleAuth . algorithm , kid : this . keyId }
6866 const privateKey = await importPKCS8 ( this . privateKey , 'ES256' )
6967
@@ -72,17 +70,17 @@ export class AppleAuth {
7270 . setIssuer ( this . teamId )
7371 . setExpirationTime ( '170days' )
7472 . setIssuedAt ( )
75- . setSubject ( this . clientId )
73+ . setSubject ( clientId )
7674 . setAudience ( AppleAuth . ENDPOINT_URL )
7775 . sign ( privateKey )
7876 }
7977
80- private async getAuthorizationToken ( code : string , clientSecret : string , redirectUri ?: string ) : Promise < AppleAuthorizationTokenResponseType > {
78+ private async getAuthorizationToken ( code : string , clientId : string , clientSecret : string , redirectUri ?: string ) : Promise < AppleAuthorizationTokenResponseType > {
8179 const url = new URL ( AppleAuth . ENDPOINT_URL )
8280 url . pathname = '/auth/token'
8381
8482 const params = new URLSearchParams ( )
85- params . append ( 'client_id' , this . clientId )
83+ params . append ( 'client_id' , clientId )
8684 params . append ( 'client_secret' , clientSecret )
8785 params . append ( 'code' , code )
8886 params . append ( 'grant_type' , 'authorization_code' )
@@ -114,11 +112,11 @@ export class AppleAuth {
114112 }
115113
116114 // Sign in with Apple
117- async loginWithApple ( code : string , idToken : string , redirectUri ?: string ) : Promise < AppleIdTokenType > {
115+ async loginWithApple ( code : string , idToken : string , clientId : string , redirectUri ?: string ) : Promise < AppleIdTokenType > {
118116 try {
119- const clientRes = await this . getClientSecret ( )
117+ const clientRes = await this . getClientSecret ( clientId )
120118
121- const tokenResp = await this . getAuthorizationToken ( code , clientRes , redirectUri )
119+ const tokenResp = await this . getAuthorizationToken ( code , clientId , clientRes , redirectUri )
122120
123121 const authResp = await this . verifyIdToken ( tokenResp . id_token )
124122
0 commit comments