Skip to content

Commit

Permalink
Merge pull request #111 from OMZigak/feat/#110-AppleLogin
Browse files Browse the repository at this point in the history
feat:애플로그인 기능 추가
  • Loading branch information
youz2me authored Jul 3, 2024
2 parents 8fed3af + ac32819 commit 275b759
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
8 changes: 6 additions & 2 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
785AE1C12C326E9B00677CA0 /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = "<group>"; };
78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; };
78B9286B2C29402C006D9942 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
78B9286D2C29402C006D9942 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,6 +143,7 @@
78B9286A2C29402C006D9942 /* KkuMulKum */ = {
isa = PBXGroup;
children = (
785AE1C12C326E9B00677CA0 /* KkuMulKum.entitlements */,
78B9286B2C29402C006D9942 /* AppDelegate.swift */,
78B9286D2C29402C006D9942 /* SceneDelegate.swift */,
78B9286F2C29402C006D9942 /* ViewController.swift */,
Expand Down Expand Up @@ -420,9 +422,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = KkuMulKum/KkuMulKum.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 2DF5SKQK2R;
DEVELOPMENT_TEAM = D2DRA3F792;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = KkuMulKum/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -448,9 +451,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = KkuMulKum/KkuMulKum.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 2DF5SKQK2R;
DEVELOPMENT_TEAM = D2DRA3F792;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = KkuMulKum/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down
10 changes: 10 additions & 0 deletions KkuMulKum/KkuMulKum.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
42 changes: 41 additions & 1 deletion KkuMulKum/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,58 @@
//
// Created by 이지훈 on 6/24/24.
//

import UIKit
import AuthenticationServices

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .yellow
setupAppleLoginButton()
}

func setupAppleLoginButton() {
let button = ASAuthorizationAppleIDButton()
button.addTarget(self, action: #selector(clickAppleLogin), for: .touchUpInside)
button.frame = CGRect(x: 100, y: 100, width: 200, height: 40)
view.addSubview(button)
}

@objc func clickAppleLogin() {
let request = ASAuthorizationAppleIDProvider().createRequest()
request.requestedScopes = [.fullName, .email]

let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
}
}

// MARK: - ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding
extension ViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let credential = authorization.credential as? ASAuthorizationAppleIDCredential {
let idToken = credential.identityToken!
let tokenStr = String(data: idToken, encoding: .utf8)
print(tokenStr ?? "No token string")

guard let code = credential.authorizationCode else { return }
let codeStr = String(data: code, encoding: .utf8)
print(codeStr ?? "No code string")

let user = credential.user
print(user)
}
}

func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
print("Authorization failed with error: \(error)")
}

func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
}

0 comments on commit 275b759

Please sign in to comment.