Skip to content

Commit 0c5e999

Browse files
authored
Apple user details (#1551)
* Adds callback to PFLoginViewController for received Apple credentials object * Adds user to Apple credential callback * Fixes target membership * Cleans up target membership * Removes CCI Carthage build dependency on iOS. iOS tests are still temperamental. * Removes @import
1 parent 46c3834 commit 0c5e999

File tree

7 files changed

+71
-64
lines changed

7 files changed

+71
-64
lines changed

.circleci/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ workflows:
7272
jobs:
7373
- ios
7474
- macos
75-
- carthage:
76-
requires:
77-
- ios
75+
- carthage
7876
nightly:
7977
jobs:
8078
- carthage

ParseUI/Classes/LogInViewController/PFLogInViewController.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ shouldBeginLogInWithUsername:(NSString *)username
179179
*/
180180
- (void)logInViewControllerDidCancelLogIn:(PFLogInViewController *)logInController;
181181

182+
/**
183+
Sent to the delegate when user data is received following successful login using Sign In With Apple.
184+
185+
@param logInController The login view controller that received the credentials
186+
@param credential The ASAuthorizationAppleIDCredential object received
187+
*/
188+
189+
-(void)logInViewController:(PFLogInViewController *)logInController didReceiveAppleCredential:(ASAuthorizationAppleIDCredential *)credential forUser:(PFUser *)user API_AVAILABLE(ios(13.0));
190+
182191
@end
183192

184193
NS_ASSUME_NONNULL_END

ParseUI/Classes/LogInViewController/PFLogInViewController.m

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "PFSignUpViewController.h"
3131
#import "PFTextField.h"
3232
#import "PFLogInView_Private.h"
33+
#import "PFAppleUtils.h"
3334

3435
NSString *const PFLogInSuccessNotification = @"com.parse.ui.login.success";
3536
NSString *const PFLogInFailureNotification = @"com.parse.ui.login.failure";
@@ -332,7 +333,7 @@ - (void)_requestPasswordResetWithEmail:(NSString *)email {
332333

333334
#pragma mark Sign in with Apple
334335
-(void)_loginWithApple API_AVAILABLE(ios(13.0)){
335-
336+
336337
if (self.loading) {
337338
return;
338339
}
@@ -344,28 +345,26 @@ -(void)_loginWithApple API_AVAILABLE(ios(13.0)){
344345

345346
__weak typeof(self) wself = self;
346347

347-
Class appleUtils = NSClassFromString(@"PFAppleUtils");
348-
SEL selector = NSSelectorFromString(@"logInInBackground");
349-
if ([appleUtils respondsToSelector:selector]) {
350-
[[appleUtils logInInBackground] continueWithBlock:^id _Nullable(BFTask * _Nonnull t) {
351-
__strong typeof(wself) sself = wself;
352-
dispatch_async(dispatch_get_main_queue(), ^{
353-
sself.loading = NO;
354-
if ([sself.logInView.appleButton isKindOfClass:[PFActionButton class]]) {
355-
[(PFActionButton *)sself.logInView.appleButton setLoading:NO];
356-
}
357-
if (t.error) {
358-
[sself _loginDidFailWithError:t.error];
359-
}
360-
else
361-
{
362-
PFUser *user = t.result[@"user"];
363-
[sself _loginDidSucceedWithUser:user];
364-
}
365-
});
366-
return nil;
367-
}];
368-
}
348+
[[PFAppleUtils logInInBackground] continueWithBlock:^id _Nullable(BFTask * _Nonnull t) {
349+
__strong typeof(wself) sself = wself;
350+
dispatch_async(dispatch_get_main_queue(), ^{
351+
sself.loading = NO;
352+
if ([sself.logInView.appleButton isKindOfClass:[PFActionButton class]]) {
353+
[(PFActionButton *)sself.logInView.appleButton setLoading:NO];
354+
}
355+
if (t.error) {
356+
[sself _loginDidFailWithError:t.error];
357+
}
358+
else
359+
{
360+
PFUser *user = t.result[PFAppleAuthUserKey];
361+
ASAuthorizationAppleIDCredential *cred = t.result[PFAppleAuthCredentialKey];
362+
[sself _loginDidSucceedWithUser:user];
363+
[sself.delegate logInViewController:sself didReceiveAppleCredential:cred forUser:user];
364+
}
365+
});
366+
return nil;
367+
}];
369368
}
370369

371370
#pragma mark Log In With Facebook

ParseUI/ParseUI.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,20 @@
184184
B9DDA283243C322D0003061D /* ParseTwitterUtils.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A51E4272027CC2D0066DE1A /* ParseTwitterUtils.framework */; };
185185
B9DDA284243C32E50003061D /* ParseFacebookUtilsV4.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A51E4362027CC330066DE1A /* ParseFacebookUtilsV4.framework */; };
186186
BC0632E023ABCC8F0089096D /* AuthenticationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC0632DC23ABCB1D0089096D /* AuthenticationServices.framework */; };
187-
BC0632E423AD005E0089096D /* PFAppleUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E323AD005E0089096D /* PFAppleUtils.m */; };
188-
BC0632E823AD03B30089096D /* PFAppleAuthenticationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E723AD03B30089096D /* PFAppleAuthenticationProvider.m */; };
189187
BC0632EA23AD3F050089096D /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A13523820282059000F5FD5 /* Bolts.framework */; };
190188
BC488EA0246B196800947E3C /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC488E9F246B196800947E3C /* ParseUI.framework */; };
191189
BC488EA1246B196800947E3C /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC488E9F246B196800947E3C /* ParseUI.framework */; };
192190
BC488EA2246B196800947E3C /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC488E9F246B196800947E3C /* ParseUI.framework */; };
193191
BC8C2923246B1873000AEE3F /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A9A9497200D0329005D8F4B /* ParseUI.framework */; };
194192
BCA5CC8523BFCFB8003BC0A0 /* SignInWithAppleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCCBE8CB23BFB89D0044A79C /* SignInWithAppleTests.m */; };
193+
BCB2A82E251D337E0030D987 /* PFAppleUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0632E223AD005E0089096D /* PFAppleUtils.h */; };
194+
BCB2A82F251D337E0030D987 /* PFAppleUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E323AD005E0089096D /* PFAppleUtils.m */; };
195+
BCB2A830251D337E0030D987 /* PFAppleAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0632E623AD03B20089096D /* PFAppleAuthenticationProvider.h */; };
196+
BCB2A831251D337E0030D987 /* PFAppleAuthenticationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E723AD03B30089096D /* PFAppleAuthenticationProvider.m */; };
197+
BCB2A840251D337F0030D987 /* PFAppleUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0632E223AD005E0089096D /* PFAppleUtils.h */; };
198+
BCB2A841251D337F0030D987 /* PFAppleUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E323AD005E0089096D /* PFAppleUtils.m */; };
199+
BCB2A842251D337F0030D987 /* PFAppleAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0632E623AD03B20089096D /* PFAppleAuthenticationProvider.h */; };
200+
BCB2A843251D337F0030D987 /* PFAppleAuthenticationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = BC0632E723AD03B30089096D /* PFAppleAuthenticationProvider.m */; };
195201
BCCBE8CE23BFB89D0044A79C /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A9A9497200D0329005D8F4B /* ParseUI.framework */; };
196202
BCCBE8E023BFC8BF0044A79C /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCCBE8DF23BFC8BF0044A79C /* OCMock.framework */; };
197203
F57F3D231B0C03D40087F60B /* DeletionCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F57F3D201B0C03C90087F60B /* DeletionCollectionViewController.m */; };
@@ -1332,6 +1338,7 @@
13321338
buildActionMask = 2147483647;
13331339
files = (
13341340
4A0ECC03200D8C0200BA84A3 /* PFLoadingView.h in Headers */,
1341+
BCB2A840251D337F0030D987 /* PFAppleUtils.h in Headers */,
13351342
4A0ECC04200D8C0200BA84A3 /* PFQueryCollectionViewController.h in Headers */,
13361343
4A0ECC05200D8C0200BA84A3 /* PFUIAlertView.h in Headers */,
13371344
4A0ECC06200D8C0200BA84A3 /* PFSignUpViewController.h in Headers */,
@@ -1344,6 +1351,7 @@
13441351
4A0ECC0D200D8C0200BA84A3 /* PFCollectionViewCell.h in Headers */,
13451352
4A0ECC0E200D8C0200BA84A3 /* PFDismissButton.h in Headers */,
13461353
4A0ECC0F200D8C0200BA84A3 /* PFActivityIndicatorCollectionReusableView.h in Headers */,
1354+
BCB2A842251D337F0030D987 /* PFAppleAuthenticationProvider.h in Headers */,
13471355
4A0ECC10200D8C0200BA84A3 /* PFQueryTableViewController.h in Headers */,
13481356
4A0ECC11200D8C0200BA84A3 /* PFLogInViewController.h in Headers */,
13491357
4A0ECC12200D8C0200BA84A3 /* PFPurchaseTableViewCell.h in Headers */,
@@ -1368,6 +1376,7 @@
13681376
buildActionMask = 2147483647;
13691377
files = (
13701378
4A9A94C6200D03BA005D8F4B /* PFLoadingView.h in Headers */,
1379+
BCB2A82E251D337E0030D987 /* PFAppleUtils.h in Headers */,
13711380
4A9A94C9200D03BE005D8F4B /* PFQueryCollectionViewController.h in Headers */,
13721381
4A9A94B6200D03B6005D8F4B /* PFUIAlertView.h in Headers */,
13731382
4A9A94AD200D03B6005D8F4B /* PFSignUpViewController.h in Headers */,
@@ -1380,6 +1389,7 @@
13801389
4A9A94A8200D03B6005D8F4B /* PFCollectionViewCell.h in Headers */,
13811390
4A9A94BE200D03BA005D8F4B /* PFDismissButton.h in Headers */,
13821391
4A9A94AF200D03B6005D8F4B /* PFActivityIndicatorCollectionReusableView.h in Headers */,
1392+
BCB2A830251D337E0030D987 /* PFAppleAuthenticationProvider.h in Headers */,
13831393
4A9A94CA200D03C8005D8F4B /* PFQueryTableViewController.h in Headers */,
13841394
4A9A94D3200D03C8005D8F4B /* PFLogInViewController.h in Headers */,
13851395
4A9A94A4200D03B6005D8F4B /* PFPurchaseTableViewCell.h in Headers */,
@@ -1826,7 +1836,9 @@
18261836
4A0ECBFC200D8C0200BA84A3 /* PFTableViewCell.m in Sources */,
18271837
4A0ECBFD200D8C0200BA84A3 /* PFLogInViewController.m in Sources */,
18281838
4A0ECBFE200D8C0200BA84A3 /* PFSignUpView.m in Sources */,
1839+
BCB2A843251D337F0030D987 /* PFAppleAuthenticationProvider.m in Sources */,
18291840
4A0ECBFF200D8C0200BA84A3 /* PFTextField.m in Sources */,
1841+
BCB2A841251D337F0030D987 /* PFAppleUtils.m in Sources */,
18301842
);
18311843
runOnlyForDeploymentPostprocessing = 0;
18321844
};
@@ -1859,7 +1871,9 @@
18591871
4A9A94A9200D03B6005D8F4B /* PFTableViewCell.m in Sources */,
18601872
4A9A94D0200D03C8005D8F4B /* PFLogInViewController.m in Sources */,
18611873
4A9A94AC200D03B6005D8F4B /* PFSignUpView.m in Sources */,
1874+
BCB2A831251D337E0030D987 /* PFAppleAuthenticationProvider.m in Sources */,
18621875
4A9A94CE200D03C8005D8F4B /* PFTextField.m in Sources */,
1876+
BCB2A82F251D337E0030D987 /* PFAppleUtils.m in Sources */,
18631877
);
18641878
runOnlyForDeploymentPostprocessing = 0;
18651879
};
@@ -1894,13 +1908,11 @@
18941908
81C5993F1A64346000F574E8 /* SimpleCollectionViewController.m in Sources */,
18951909
81472FBB1A1AB37500FD6EED /* main.m in Sources */,
18961910
81C599421A6454C900F574E8 /* PaginatedCollectionViewController.m in Sources */,
1897-
BC0632E423AD005E0089096D /* PFAppleUtils.m in Sources */,
18981911
81472FB31A1AB37500FD6EED /* CustomSignUpViewController.m in Sources */,
18991912
81472FB41A1AB37500FD6EED /* CustomLogInViewController.m in Sources */,
19001913
81472FB91A1AB37500FD6EED /* CustomProductTableViewController.m in Sources */,
19011914
819A4B3A1A6808EA00D01241 /* SubtitleImageCollectionViewController.m in Sources */,
19021915
F57F3D241B0C03DB0087F60B /* DeletionTableViewController.m in Sources */,
1903-
BC0632E823AD03B30089096D /* PFAppleAuthenticationProvider.m in Sources */,
19041916
812E5C041A7A8EFB000FBDE1 /* StoryboardCollectionViewController.m in Sources */,
19051917
81472FB51A1AB37500FD6EED /* SimpleTableViewController.m in Sources */,
19061918
F57F3D231B0C03D40087F60B /* DeletionCollectionViewController.m in Sources */,

ParseUI/Sign In With Apple/PFAppleUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
NS_ASSUME_NONNULL_BEGIN
1616

1717
extern NSString *const PFAppleUserAuthenticationType;
18+
extern NSString *const PFAppleAuthUserKey;
19+
extern NSString *const PFAppleAuthCredentialKey;
1820

1921
API_AVAILABLE(ios(13.0))
2022
@interface PFAppleLoginManager : NSObject <ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>

ParseUI/Sign In With Apple/PFAppleUtils.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
#import "PFAppleUtils.h"
1010
#import "PFAppleAuthenticationProvider.h"
11-
@import AuthenticationServices;
11+
#import <AuthenticationServices/AuthenticationServices.h>
1212
#import <Bolts/Bolts.h>
1313

1414
NSString *const PFAppleUserAuthenticationType = @"apple";
15+
NSString *const PFAppleAuthUserKey = @"user";
16+
NSString *const PFAppleAuthCredentialKey = @"credential";
1517

1618
API_AVAILABLE(ios(13.0))
1719
@interface PFAppleLoginManager ()
@@ -46,17 +48,16 @@ - (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:(no
4648
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization {
4749
ASAuthorizationAppleIDCredential *cred = authorization.credential;
4850
NSString *userId = cred.user;
49-
NSPersonNameComponents *fullName = cred.fullName;
5051
NSData *token = cred.identityToken;
5152
NSString *tokenString = [[NSString alloc] initWithData:token encoding:NSUTF8StringEncoding];
5253

5354
__weak typeof(self) wself = self;
5455

55-
[[[PFUser logInWithAuthTypeInBackground:@"apple"
56+
[[[PFUser logInWithAuthTypeInBackground:PFAppleUserAuthenticationType
5657
authData:@{@"token" : tokenString, @"id" : userId}] continueWithSuccessBlock:^id _Nullable(BFTask<__kindof PFUser *> * _Nonnull t) {
5758
__strong typeof(wself) sself = wself;
58-
[sself.completionSource setResult:@{@"user" : t.result,
59-
@"name" : fullName}];
59+
[sself.completionSource setResult:@{PFAppleAuthUserKey : t.result,
60+
PFAppleAuthCredentialKey : cred}];
6061
sself.strongSelf = nil;
6162
return t;
6263
}] continueWithBlock:^id _Nullable(BFTask * _Nonnull t) {

ParseUI/SignInWithAppleTests/SignInWithAppleTests.m

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "PFAppleUtils.h"
11+
#import "Parse/PFUser.h"
12+
#import "PFLoginViewController.h"
13+
1114
@import OCMock;
1215

1316
@interface SignInWithAppleTests : XCTestCase
@@ -59,7 +62,7 @@ - (void)tearDown {
5962
// Put teardown code here. This method is called after the invocation of each test method in the class.
6063
}
6164

62-
- (void)testLoginSuccess {
65+
- (void)testAppleUtilsLoginSuccess {
6366

6467
// Create test ASAuthorization and ASAuthorizationAppleIDCredential
6568
FakeAuth *fakeAuth = [FakeAuth new];
@@ -78,29 +81,33 @@ - (void)testLoginSuccess {
7881
id mockUser = OCMClassMock([PFUser class]);
7982
NSDictionary *authData = @{@"token" : aString,
8083
@"id" : aString };
81-
NSDictionary *result = @{ @"user" : aString,
82-
@"name" : name };
83-
OCMStub(ClassMethod([mockUser logInWithAuthTypeInBackground:@"apple" authData:authData])).andReturn([BFTask taskWithResult:result]);
84+
PFUser *loggedInUser = [PFUser new];
85+
OCMStub(ClassMethod([mockUser logInWithAuthTypeInBackground:@"apple" authData:authData])).andReturn([BFTask taskWithResult:loggedInUser]);
8486

8587
// Create the login task
8688
PFAppleLoginManager *manager = [PFAppleLoginManager new];
8789
BFTask<NSDictionary *> *logInTask = [PFAppleUtils logInInBackgroundWithManager:manager];
8890

89-
XCTestExpectation *expect = [self expectationWithDescription:@"Task should complete."];
91+
XCTestExpectation *expectLoginSuccess = [self expectationWithDescription:@"Login should complete."];
9092
[logInTask continueWithSuccessBlock:^id _Nullable(BFTask<NSDictionary *> * _Nonnull t) {
91-
[expect fulfill];
93+
XCTAssert(t.result[@"user"] == loggedInUser);
94+
ASAuthorizationAppleIDCredential *credential = t.result[@"credential"];
95+
XCTAssert([credential.fullName isEqual:cred.fullName]);
96+
XCTAssert([credential.identityToken isEqual:cred.identityToken]);
97+
XCTAssert([credential.user isEqual:cred.user]);
98+
[expectLoginSuccess fulfill];
9299
return nil;
93100
}];
94101

95102
// Call the success callback as Apple would
96103
[manager authorizationController:manager.controller didCompleteWithAuthorization:(ASAuthorization *)fakeAuth];
97-
[self waitForExpectations:@[expect] timeout:2];
104+
[self waitForExpectations:@[expectLoginSuccess] timeout:2];
98105

99106
[mockUser stopMocking];
100107

101108
}
102109

103-
- (void)testPFUserLoginFails {
110+
- (void)testAppleUtilsLoginFailure {
104111
// Create test ASAuthorization and ASAuthorizationAppleIDCredential
105112
FakeAuth *fakeAuth = [FakeAuth new];
106113
FakeCredential *cred = [FakeCredential new];
@@ -140,25 +147,4 @@ - (void)testPFUserLoginFails {
140147
[mockUser stopMocking];
141148
}
142149

143-
- (void)testAppleAuthCompletesWithError {
144-
145-
// Create the login task
146-
PFAppleLoginManager *manager = [PFAppleLoginManager new];
147-
BFTask<NSDictionary *> *logInTask = [PFAppleUtils logInInBackgroundWithManager:manager];
148-
149-
XCTestExpectation *expect = [self expectationWithDescription:@"Task should fail."];
150-
[logInTask continueWithBlock:^id _Nullable(BFTask<NSDictionary *> * _Nonnull t) {
151-
if (t.error) {
152-
[expect fulfill];
153-
}
154-
return nil;
155-
}];
156-
157-
// Call the failure callback as Apple would
158-
NSError *err = [[NSError alloc] initWithDomain:@"org.parseplatform.error" code:1337 userInfo:nil];
159-
[manager authorizationController:manager.controller didCompleteWithError:err];
160-
[self waitForExpectations:@[expect] timeout:2];
161-
162-
}
163-
164150
@end

0 commit comments

Comments
 (0)