Commit 8519d77b authored by Steven杜宇's avatar Steven杜宇

// 苹果登录

parent 908d542d
......@@ -289,6 +289,7 @@
04EA376F2BEA071600DBAF64 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 04EA376E2BEA070500DBAF64 /* libc++.tbd */; };
04EA37742BEA0A3400DBAF64 /* YHShareManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04EA37732BEA0A3400DBAF64 /* YHShareManager.swift */; };
04F4B76B2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F4B76A2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift */; };
04FA8B2B2C06F59D00ABE43F /* YHAppleLoginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */; };
6203A87EDC96313BBE789D9C /* Pods_galaxy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */; };
A51044182B493675006B60BB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = A51044172B493675006B60BB /* README.md */; };
A510441A2B495DD0006B60BB /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51044192B495DD0006B60BB /* UIView+Extension.swift */; };
......@@ -756,6 +757,7 @@
04EA376E2BEA070500DBAF64 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
04EA37732BEA0A3400DBAF64 /* YHShareManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareManager.swift; sourceTree = "<group>"; };
04F4B76A2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateTemplateSheetView.swift; sourceTree = "<group>"; };
04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAppleLoginManager.swift; sourceTree = "<group>"; };
19B28612265782F9DC1BE0B0 /* Pods-galaxy.testenv.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.testenv.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.testenv.xcconfig"; sourceTree = "<group>"; };
58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; };
987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_galaxy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -1729,6 +1731,7 @@
isa = PBXGroup;
children = (
0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */,
04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */,
);
path = C;
sourceTree = "<group>";
......@@ -2980,6 +2983,7 @@
A517A4E12BB573EB000DEECD /* YHDocListCell.swift in Sources */,
A58037212BAD7B2A0031C312 /* YHMySchemeModel.swift in Sources */,
0493B3DE2BA80C2300AF9393 /* YHCertificateFilterButton.swift in Sources */,
04FA8B2B2C06F59D00ABE43F /* YHAppleLoginManager.swift in Sources */,
A567E5932BD7643D00D5D5A0 /* YHHomePageViewModel.swift in Sources */,
045EEE822B9F171A0022A143 /* YHPersonInfoIdentityCardModel.swift in Sources */,
045EEE952B9F171A0022A143 /* YHPreviewInfoCertificateInformationItemsView.swift in Sources */,
......
//
// YHAppleLoginManager.swift
// galaxy
//
// Created by edy on 2024/5/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import AuthenticationServices
class YHAppleLoginManager: NSObject {
func appleLogin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let vc = ASAuthorizationController(authorizationRequests: [request])
vc.delegate = self
vc.presentationContextProvider = self
vc.performRequests()
}
}
extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
// 其中`authorization.credential`包含了Token,用户ID等授权所需信息,可上报到后台
let credential = authorization.credential
if credential is ASPasswordCredential {
let passwdCredential = credential as! ASPasswordCredential
let userIdentifier = passwdCredential.user
let username = passwdCredential.user
let password = passwdCredential.password
printLog("username:\(username), passwd:\(password)")
} else if credential is ASAuthorizationAppleIDCredential {
let appleIdCredential = credential as! ASAuthorizationAppleIDCredential
let userIdentifier = appleIdCredential.user
let fullName = appleIdCredential.fullName
let email = appleIdCredential.email ?? "email"
let authorizationCode = appleIdCredential.authorizationCode
let authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
let identityToken = appleIdCredential.identityToken
let identityTokenStr = String(decoding: identityToken!, as: UTF8.self)
let realUserStatus = appleIdCredential.realUserStatus
printLog("authorizationCodeStr: \(authorizationCodeStr)")
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
printLog("FAILED: \(error.localizedDescription)")
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return UIApplication.shared.yhKeyWindow()!
}
}
......@@ -27,12 +27,11 @@ class YHAppleLoginViewController: YHBaseViewController {
@objc func didAppleIDBtnClicked() {
let provider = ASAuthorizationAppleIDProvider()
let request = provider.createRequest()
request.requestedScopes = [ASAuthorization.Scope.fullName,
ASAuthorization.Scope.email]
let keychainRequest = ASAuthorizationPasswordProvider().createRequest()
let vc = ASAuthorizationController(authorizationRequests: [request, keychainRequest])
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
// let keychainRequest = ASAuthorizationPasswordProvider().createRequest()
let vc = ASAuthorizationController(authorizationRequests: [request])
vc.delegate = self
vc.presentationContextProvider = self
vc.performRequests()
......@@ -44,11 +43,31 @@ extension YHAppleLoginViewController: ASAuthorizationControllerDelegate, ASAutho
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
// 其中`authorization.credential`包含了Token,用户ID等授权所需信息,可上报到后台
let credential = authorization.credential
if credential is ASPasswordCredential {
let passwdCredential = credential as! ASPasswordCredential
let userIdentifier = passwdCredential.user
let username = passwdCredential.user
let password = passwdCredential.password
printLog("username:\(username), passwd:\(password)")
} else if credential is ASAuthorizationAppleIDCredential {
let appleIdCredential = credential as! ASAuthorizationAppleIDCredential
let userIdentifier = appleIdCredential.user
let fullName = appleIdCredential.fullName
let email = appleIdCredential.email ?? "email"
let authorizationCode = appleIdCredential.authorizationCode
let authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
let identityToken = appleIdCredential.identityToken
let identityTokenStr = String(decoding: identityToken!, as: UTF8.self)
let realUserStatus = appleIdCredential.realUserStatus
printLog("authorizationCodeStr: \(authorizationCodeStr)")
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
printLog("FAILED: \(error.localizedDescription)")
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment