Skip to content

Instantly share code, notes, and snippets.

@furydeveloper
furydeveloper / AppDelegate.swift
Created August 19, 2020 05:07
AppDelegate.swift
import KakaoSDKCommon
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
KakaoSDKCommon.initSDK(appKey: "NATIVE_APP_KEY")
...
}
@furydeveloper
furydeveloper / SceneDelegate.swift
Created August 19, 2020 04:42
SceneDelegate.swift
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)
}
@furydeveloper
furydeveloper / AppDelegate.swift
Created August 19, 2020 04:39
AppDelegate.swift
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)
}
@furydeveloper
furydeveloper / SceneDelegate.swift
Created June 23, 2020 04:18
SceneDelegate.swift
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 {
@furydeveloper
furydeveloper / SceneDelegate.swift
Created June 23, 2020 02:15
SceneDelegate.swift
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
NaverThirdPartyLoginConnection
.getSharedInstance()?
.receiveAccessToken(URLContexts.first?.url)
}
@furydeveloper
furydeveloper / ViewController.swift
Created March 14, 2020 15:19
ViewController.swift
extension ViewController: ASAuthorizationControllerPresentationContextProviding {
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
}
@furydeveloper
furydeveloper / ViewController.swift
Created March 14, 2020 14:14
ViewController.swift
@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")
@furydeveloper
furydeveloper / ViewController.swift
Created March 14, 2020 12:41
ViewController.swift
// 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]
@furydeveloper
furydeveloper / ViewController.swift
Created March 14, 2020 10:06
ViewController.swift
// 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
@furydeveloper
furydeveloper / SelfCertificationViewController.swift
Created January 12, 2020 02:34
SelfCertificationViewController.swift
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)
})