This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import KakaoSDKCommon | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
... | |
KakaoSDKCommon.initSDK(appKey: "NATIVE_APP_KEY") | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import KakaoSDKAuth | |
... | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
... | |
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | |
if let url = URLContexts.first?.url { | |
if (AuthApi.isKakaoTalkLoginUrl(url)) { | |
_ = AuthController.handleOpenUrl(url: url) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import KakaoSDKAuth | |
... | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
... | |
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { | |
if (AuthApi.isKakaoTalkLoginUrl(url)) { | |
return AuthController.handleOpenUrl(url: url) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sceneDidEnterBackground(_ scene: UIScene) { | |
KOSession.handleDidEnterBackground() | |
} | |
func sceneDidBecomeActive(_ scene: UIScene) { | |
KOSession.handleDidBecomeActive() | |
} | |
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | |
if let url = URLContexts.first?.url { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | |
NaverThirdPartyLoginConnection | |
.getSharedInstance()? | |
.receiveAccessToken(URLContexts.first?.url) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: ASAuthorizationControllerPresentationContextProviding { | |
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { | |
return self.view.window! | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(iOS 13.0, *) | |
extension MainViewController: ASAuthorizationControllerDelegate { | |
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { | |
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { | |
guard let nonce = currentNonce else { | |
fatalError("Invalid state: A login callback was received, but no login request was sent.") | |
} | |
guard let appleIDToken = appleIDCredential.identityToken else { | |
print("Unable to fetch identity token") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unhashed nonce. | |
fileprivate var currentNonce: String? | |
@available(iOS 13, *) | |
func startSignInWithAppleFlow() { | |
let nonce = randomNonceString() | |
currentNonce = nonce | |
let appleIDProvider = ASAuthorizationAppleIDProvider() | |
let request = appleIDProvider.createRequest() | |
request.requestedScopes = [.fullName, .email] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from https://auth0.com/docs/api-auth/tutorials/nonce#generate-a-cryptographically-random-nonce | |
private func randomNonceString(length: Int = 32) -> String { | |
precondition(length > 0) | |
let charset: Array<Character> = | |
Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._") | |
var result = "" | |
var remainingLength = length | |
while remainingLength > 0 { | |
let randoms: [UInt8] = (0 ..< 16).map { _ in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.view.window?.rootViewController?.dismiss(animated: false, completion: { | |
let homeVC = HomeViewController() | |
homeVC.modalPresentationStyle = .fullScreen | |
let appDelegate = UIApplication.shared.delegate as! AppDelegate | |
appDelegate.window?.rootViewController?.present(homeVC, animated: true, completion: nil) | |
}) |
NewerOlder