forked from organicmaps/organicmaps
[iOS] pass user name on Sign in with Apple
Also implement log out if Apple Id authorization revoked
This commit is contained in:
parent
cb762c2bef
commit
485d506048
8 changed files with 72 additions and 7 deletions
|
@ -23,12 +23,15 @@ NS_SWIFT_NAME(User)
|
|||
+ (BOOL)isAuthenticated;
|
||||
+ (NSString *)termsOfUseLink;
|
||||
+ (NSString *)privacyPolicyLink;
|
||||
+ (void)logOut;
|
||||
|
||||
+ (void)authenticateWithToken:(NSString *)token
|
||||
type:(MWMSocialTokenType)type
|
||||
privacyAccepted:(BOOL)privacyAccepted
|
||||
termsAccepted:(BOOL)termsAccepted
|
||||
promoAccepted:(BOOL)promoAccepted
|
||||
firstName:(NSString *)firstName
|
||||
lastName:(NSString *)lastName
|
||||
source:(MWMAuthorizationSource)source
|
||||
onComplete:(MWMBoolBlock)onComplete;
|
||||
|
||||
|
|
|
@ -20,11 +20,17 @@
|
|||
return @(User::GetPrivacyPolicyLink().c_str());
|
||||
}
|
||||
|
||||
+ (void)logOut {
|
||||
GetFramework().GetUser().ResetAccessToken();
|
||||
}
|
||||
|
||||
+ (void)authenticateWithToken:(NSString *)token
|
||||
type:(MWMSocialTokenType)type
|
||||
privacyAccepted:(BOOL)privacyAccepted
|
||||
termsAccepted:(BOOL)termsAccepted
|
||||
promoAccepted:(BOOL)promoAccepted
|
||||
firstName:(NSString *)firstName
|
||||
lastName:(NSString *)lastName
|
||||
source:(MWMAuthorizationSource)source
|
||||
onComplete:(MWMBoolBlock)onComplete {
|
||||
auto &user = GetFramework().GetUser();
|
||||
|
@ -52,7 +58,8 @@
|
|||
});
|
||||
};
|
||||
user.AddSubscriber(std::move(s));
|
||||
user.Authenticate(token.UTF8String, socialTokenType, privacyAccepted, termsAccepted, promoAccepted);
|
||||
user.Authenticate(token.UTF8String, socialTokenType, privacyAccepted, termsAccepted, promoAccepted,
|
||||
firstName.UTF8String, lastName.UTF8String);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -279,6 +279,9 @@ using namespace osm_auth_ios;
|
|||
[MoPubKit grantConsent];
|
||||
|
||||
[[DeepLinkHandler shared] applicationDidFinishLaunching:launchOptions];
|
||||
if (@available(iOS 13, *)) {
|
||||
[MWMUser verifyAppleId];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -370,6 +370,7 @@
|
|||
478F6FA423C447E500054A53 /* ReviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 478F6FA323C447E500054A53 /* ReviewView.swift */; };
|
||||
478F6FA623C4521F00054A53 /* MoreReviewsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 478F6FA523C4521F00054A53 /* MoreReviewsViewController.swift */; };
|
||||
478F6FA823C5067C00054A53 /* MyReviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 478F6FA723C5067C00054A53 /* MyReviewView.swift */; };
|
||||
479603732446F17C00F3BDD0 /* User+AppleId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 479603722446F17C00F3BDD0 /* User+AppleId.swift */; };
|
||||
479D305722C627CB00D18278 /* PartnerBannerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 479D305522C627CB00D18278 /* PartnerBannerViewController.xib */; };
|
||||
479D305B22C62F4000D18278 /* MWMBookmarksBannerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 479D305922C62F4000D18278 /* MWMBookmarksBannerViewController.xib */; };
|
||||
479D306522C664CE00D18278 /* MWMDownloadBannerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 479D306422C664CE00D18278 /* MWMDownloadBannerViewController.m */; };
|
||||
|
@ -1472,6 +1473,7 @@
|
|||
478F6FA323C447E500054A53 /* ReviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewView.swift; sourceTree = "<group>"; };
|
||||
478F6FA523C4521F00054A53 /* MoreReviewsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreReviewsViewController.swift; sourceTree = "<group>"; };
|
||||
478F6FA723C5067C00054A53 /* MyReviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyReviewView.swift; sourceTree = "<group>"; };
|
||||
479603722446F17C00F3BDD0 /* User+AppleId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "User+AppleId.swift"; sourceTree = "<group>"; };
|
||||
479D305522C627CB00D18278 /* PartnerBannerViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PartnerBannerViewController.xib; sourceTree = "<group>"; };
|
||||
479D305922C62F4000D18278 /* MWMBookmarksBannerViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MWMBookmarksBannerViewController.xib; sourceTree = "<group>"; };
|
||||
479D306322C664CE00D18278 /* MWMDownloadBannerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMDownloadBannerViewController.h; sourceTree = "<group>"; };
|
||||
|
@ -3223,6 +3225,7 @@
|
|||
34BBD64A1F826DB10070CA50 /* AuthorizationViewController.swift */,
|
||||
34BBD6661F8273350070CA50 /* AuthorizationViewController.xib */,
|
||||
47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */,
|
||||
479603722446F17C00F3BDD0 /* User+AppleId.swift */,
|
||||
);
|
||||
path = Authorization;
|
||||
sourceTree = "<group>";
|
||||
|
@ -5542,6 +5545,7 @@
|
|||
993F550B237C622700545511 /* DeepLinkIncorrectStrategy.swift in Sources */,
|
||||
34BBD65C1F826FD30070CA50 /* AuthorizationiPhonePresentationController.swift in Sources */,
|
||||
56C74C391C74A3BC00B71B9F /* MWMInputEmailValidator.m in Sources */,
|
||||
479603732446F17C00F3BDD0 /* User+AppleId.swift in Sources */,
|
||||
993DF0CB23F6BD0600AC231A /* ElevationDetailsRouter.swift in Sources */,
|
||||
6741A9F51BF340DE002C974C /* BookmarksVC.mm in Sources */,
|
||||
B33D21B820E130D000BAD749 /* BookmarksTabViewController.swift in Sources */,
|
||||
|
|
|
@ -239,7 +239,11 @@ final class AuthorizationViewController: MWMViewController {
|
|||
Crashlytics.sharedInstance().recordError(error)
|
||||
}
|
||||
|
||||
private func process(token: String, type: SocialTokenType) {
|
||||
private func process(token: String,
|
||||
type: SocialTokenType,
|
||||
firstName: String = "",
|
||||
lastName: String = "",
|
||||
completion: ((_ success: Bool) -> Void)? = nil) {
|
||||
Statistics.logEvent(kStatUGCReviewAuthExternalRequestSuccess,
|
||||
withParameters: [kStatProvider: getProviderStatStr(type: type)])
|
||||
User.authenticate(withToken: token,
|
||||
|
@ -247,7 +251,10 @@ final class AuthorizationViewController: MWMViewController {
|
|||
privacyAccepted: privacyPolicyCheck.isChecked,
|
||||
termsAccepted: termsOfUseCheck.isChecked,
|
||||
promoAccepted: latestNewsCheck.isChecked,
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
source: sourceComponent) { success in
|
||||
completion?(success)
|
||||
self.logStats(type: type, success: success)
|
||||
if success {
|
||||
self.successHandler?(type)
|
||||
|
@ -317,8 +324,15 @@ extension AuthorizationViewController: ASAuthorizationControllerDelegate {
|
|||
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
||||
switch authorization.credential {
|
||||
case let appleIDCredential as ASAuthorizationAppleIDCredential:
|
||||
guard let token = appleIDCredential.identityToken, let tokenString = String(data: token, encoding: .utf8) else { return }
|
||||
process(token: tokenString, type: .apple)
|
||||
guard let token = appleIDCredential.identityToken,
|
||||
let tokenString = String(data: token, encoding: .utf8),
|
||||
let fullName = appleIDCredential.fullName else { return }
|
||||
let appleId = appleIDCredential.user
|
||||
process(token: tokenString, type: .apple, firstName: fullName.givenName ?? "", lastName: fullName.familyName ?? "") {
|
||||
if $0 {
|
||||
User.setAppleId(appleId)
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
26
iphone/Maps/UI/Authorization/User+AppleId.swift
Normal file
26
iphone/Maps/UI/Authorization/User+AppleId.swift
Normal file
|
@ -0,0 +1,26 @@
|
|||
import Foundation
|
||||
|
||||
fileprivate enum Const {
|
||||
static let kAppleIdKey = "kAppleIdKey"
|
||||
}
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
extension User {
|
||||
static func setAppleId(_ appleId: String) {
|
||||
UserDefaults.standard.set(appleId, forKey: Const.kAppleIdKey)
|
||||
}
|
||||
|
||||
@objc static func verifyAppleId() {
|
||||
guard let appleId = UserDefaults.standard.string(forKey: Const.kAppleIdKey) else { return }
|
||||
let appleIDProvider = ASAuthorizationAppleIDProvider()
|
||||
appleIDProvider.getCredentialState(forUserID: appleId) { (state, error) in
|
||||
switch state {
|
||||
case .revoked, .notFound:
|
||||
logOut()
|
||||
UserDefaults.standard.set(nil, forKey: Const.kAppleIdKey)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
map/user.cpp
11
map/user.cpp
|
@ -196,6 +196,8 @@ struct SocialNetworkAuthRequestData
|
|||
bool m_privacyAccepted = false;
|
||||
bool m_termsAccepted = false;
|
||||
bool m_promoAccepted = false;
|
||||
std::string m_firstName;
|
||||
std::string m_lastName;
|
||||
|
||||
DECLARE_VISITOR(visitor(m_accessToken, "access_token"),
|
||||
visitor(m_clientId, "client_id"),
|
||||
|
@ -203,7 +205,9 @@ struct SocialNetworkAuthRequestData
|
|||
visitor(m_termsLink, "terms_link"),
|
||||
visitor(m_privacyAccepted, "privacy_accepted"),
|
||||
visitor(m_termsAccepted, "terms_accepted"),
|
||||
visitor(m_promoAccepted, "promo_accepted"))
|
||||
visitor(m_promoAccepted, "promo_accepted"),
|
||||
visitor(m_firstName, "first_name"),
|
||||
visitor(m_lastName, "last_name"))
|
||||
};
|
||||
|
||||
struct UserDetailsResponseData
|
||||
|
@ -340,7 +344,8 @@ void User::SetAccessToken(std::string const & accessToken)
|
|||
}
|
||||
|
||||
void User::Authenticate(std::string const & socialToken, SocialTokenType socialTokenType,
|
||||
bool privacyAccepted, bool termsAccepted, bool promoAccepted)
|
||||
bool privacyAccepted, bool termsAccepted, bool promoAccepted,
|
||||
std::string const & firstName, std::string const & lastName)
|
||||
{
|
||||
std::string const url = AuthenticationUrl(socialToken, socialTokenType);
|
||||
if (url.empty())
|
||||
|
@ -371,6 +376,8 @@ void User::Authenticate(std::string const & socialToken, SocialTokenType socialT
|
|||
authData.m_termsAccepted = termsAccepted;
|
||||
authData.m_privacyAccepted = privacyAccepted;
|
||||
authData.m_promoAccepted = promoAccepted;
|
||||
authData.m_firstName = firstName;
|
||||
authData.m_lastName = lastName;
|
||||
authParams = [authData = std::move(authData)](platform::HttpClient & request)
|
||||
{
|
||||
auto jsonData = SerializeToJson(authData);
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
|
||||
User();
|
||||
void Authenticate(std::string const & socialToken, SocialTokenType socialTokenType,
|
||||
bool privacyAccepted, bool termsAccepted, bool promoAccepted);
|
||||
bool privacyAccepted, bool termsAccepted, bool promoAccepted,
|
||||
std::string const & firstName = "", std::string const & lastName = "");
|
||||
bool IsAuthenticated() const;
|
||||
void ResetAccessToken();
|
||||
void UpdateUserDetails();
|
||||
|
|
Loading…
Add table
Reference in a new issue