3
This commit is contained in:
@@ -43,27 +43,29 @@
|
||||
if (identityToken.length) params[@"identityToken"] = identityToken;
|
||||
if (authorizationCode.length) params[@"accessCode"] = authorizationCode; // 仅供后端需要时使用
|
||||
if (cred.user.length) params[@"userID"] = cred.user; // 可选
|
||||
|
||||
[KBHUD show];
|
||||
// 向服务端发起校验
|
||||
[[KBNetworkManager shared] POST:API_APPLE_LOGIN jsonBody:params headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
if (error) { if (completion) completion(NO, error); return; }
|
||||
|
||||
// 从返回 JSON 中提取 token(支持常见命名与层级 data/user)
|
||||
// 先解析用户模型(使用 MJExtension)
|
||||
KBUser *user = [KBUser userFromResponseObject:jsonOrData];
|
||||
NSDictionary *dict = jsonOrData[@"data"];
|
||||
KBUser *user = [KBUser mj_objectWithKeyValues:dict];
|
||||
self.currentUser = user;
|
||||
NSString *token = user.token ?: [self.class tokenFromResponseObject:jsonOrData];
|
||||
if (token.length == 0) {
|
||||
if (user.token.length == 0) {
|
||||
if (completion) completion(NO, [NSError errorWithDomain:@"KBLogin" code:-2 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"No token returned")}]);
|
||||
return;
|
||||
}
|
||||
|
||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||
completion(true,nil);
|
||||
// 保存登录态到共享钥匙串;供 App 与扩展共享
|
||||
BOOL ok = [[KBAuthManager shared] saveAccessToken:token
|
||||
refreshToken:nil
|
||||
expiryDate:nil
|
||||
userIdentifier:cred.user];
|
||||
if (completion) completion(ok, ok ? nil : [NSError errorWithDomain:@"KBLogin" code:-3 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Failed to save login state")}]);
|
||||
// BOOL ok = [[KBAuthManager shared] saveAccessToken:user.token
|
||||
// refreshToken:nil
|
||||
// expiryDate:nil
|
||||
// userIdentifier:cred.user];
|
||||
// if (completion) completion(ok, ok ? nil : [NSError errorWithDomain:@"KBLogin" code:-3 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Failed to save login state")}]);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user