@@ -242,6 +242,28 @@ class AuthenticationSpec: QuickSpec {
242
242
" scope " : " openid email " ,
243
243
" audience " : " https://myapi.com/api "
244
244
] ) ) { _ in return authResponse ( accessToken: AccessToken, idToken: IdToken) } . name = " Token Exchange Apple Success with custom scope and audience "
245
+
246
+ stub ( condition: isToken ( Domain) && hasAtLeast ( [
247
+ " grant_type " : " urn:ietf:params:oauth:grant-type:token-exchange " ,
248
+ " subject_token " : " VALIDNAMECODE " ,
249
+ " subject_token_type " : " http://auth0.com/oauth/token-type/apple-authz-code " ] ) &&
250
+ ( hasAtLeast ( [ " user_profile " : " { \" name \" :{ \" lastName \" : \" Smith \" , \" firstName \" : \" John \" }} " ] ) || hasAtLeast ( [ " user_profile " : " { \" name \" :{ \" firstName \" : \" John \" , \" lastName \" : \" Smith \" }} " ] ) )
251
+ ) { _ in return authResponse ( accessToken: AccessToken, idToken: IdToken) } . name = " Token Exchange Apple Success with user profile "
252
+
253
+ stub ( condition: isToken ( Domain) && hasAtLeast ( [
254
+ " grant_type " : " urn:ietf:params:oauth:grant-type:token-exchange " ,
255
+ " subject_token " : " VALIDPARTIALNAMECODE " ,
256
+ " subject_token_type " : " http://auth0.com/oauth/token-type/apple-authz-code " ,
257
+ " user_profile " : " { \" name \" :{ \" firstName \" : \" John \" }} "
258
+ ] ) ) { _ in return authResponse ( accessToken: AccessToken, idToken: IdToken) } . name = " Token Exchange Apple Success with partial user profile "
259
+
260
+ stub ( condition: isToken ( Domain) && hasAtLeast ( [
261
+ " grant_type " : " urn:ietf:params:oauth:grant-type:token-exchange " ,
262
+ " subject_token " : " VALIDMISSINGNAMECODE " ,
263
+ " subject_token_type " : " http://auth0.com/oauth/token-type/apple-authz-code " ] ) &&
264
+ hasNoneOf ( [ " user_profile " ] )
265
+ ) { _ in return authResponse ( accessToken: AccessToken, idToken: IdToken) } . name = " Token Exchange Apple Success with missing user profile "
266
+
245
267
}
246
268
247
269
it ( " should exchange apple auth code for credentials " ) {
@@ -284,8 +306,56 @@ class AuthenticationSpec: QuickSpec {
284
306
}
285
307
}
286
308
287
- }
309
+ it ( " should exchange apple auth code for credentials with fullName " ) {
310
+ var fullName = PersonNameComponents ( )
311
+ fullName. givenName = " John "
312
+ fullName. familyName = " Smith "
313
+ fullName. middleName = " Ignored "
288
314
315
+ waitUntil ( timeout: Timeout) { done in
316
+ auth. tokenExchange ( withAppleAuthorizationCode: " VALIDNAMECODE " ,
317
+ fullName: fullName)
318
+ . start { result in
319
+ expect ( result) . to ( haveCredentials ( ) )
320
+ done ( )
321
+ }
322
+ }
323
+ }
324
+
325
+ it ( " should exchange apple auth code for credentials with partial fullName " ) {
326
+ var fullName = PersonNameComponents ( )
327
+ fullName. givenName = " John "
328
+ fullName. familyName = nil
329
+ fullName. middleName = " Ignored "
330
+
331
+ waitUntil ( timeout: Timeout) { done in
332
+ auth. tokenExchange ( withAppleAuthorizationCode: " VALIDPARTIALNAMECODE " ,
333
+ fullName: fullName)
334
+ . start { result in
335
+ expect ( result) . to ( haveCredentials ( ) )
336
+ done ( )
337
+ }
338
+ }
339
+ }
340
+
341
+ it ( " should exchange apple auth code for credentials with missing fullName " ) {
342
+ var fullName = PersonNameComponents ( )
343
+ fullName. givenName = nil
344
+ fullName. familyName = nil
345
+ fullName. middleName = nil
346
+
347
+ waitUntil ( timeout: Timeout) { done in
348
+ auth. tokenExchange ( withAppleAuthorizationCode: " VALIDMISSINGNAMECODE " ,
349
+ fullName: fullName)
350
+ . start { result in
351
+ expect ( result) . to ( haveCredentials ( ) )
352
+ done ( )
353
+ }
354
+ }
355
+ }
356
+
357
+ }
358
+
289
359
describe ( " revoke refresh token " ) {
290
360
291
361
let refreshToken = UUID ( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
0 commit comments