일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- Tuist
- .pbxproj
- github 시작하기
- NVME
- 코드스쿼드
- TestFlight
- swift 모듈화
- 클린 아키텍처
- 캐러셀
- 팀 개발을 위한 git
- 무한스크롤
- png
- xcode 엔터 표시
- spm 에러
- 테스트 타겟
- swiftdata
- fetchdescriptor
- 메모이제이션
- xcode 공백 표시
- contentalignmentpoint
- JPEG
- JPG
- 함께자라기
- 타뷸레이션
- SwiftUI
- Cocoa Pod
- Firestore
- webp
- nidthirdpartylogin
- heic
- Today
- Total
Sure, Why not?
Google 로그인 본문
iOS 및 macOS용 Google 로그인 시작하기 | Authentication | Google for Developers
Important: Starting May 1, 2024, Apple requires Privacy Manifests and signatures for iOS applications that use commonly-used SDKs, including GoogleSignIn-iOS. Upgrade to GoogleSignIn-iOS v7.1.0+ before May 1, 2024. Follow our upgrade guide. 이 페이지
developers.google.com
GoogleSignIn 종속성 설치
https://github.com/google/GoogleSignIn-iOS
SPM로 설치하였다.
OAuth 클라이언트 ID 가져오기
파란색 버튼 눌러서 ID 생성해준다.
그리고 credentials.plist 다운받아서
클라이언트 ID와 스키마 주소를 확인한다.
(혹여나 다운 못받아도 흰색버튼 누르고 클라이언트에서 OAuth 클라이언트 다운로드에서 plist파일 받을 수 있음)
역시나 노출이 안되는 정보이기 때문에 환경변수로 관리를 한다.
그리고 Info.plist에서는
key값인 GIDClientID와
value값인 client ID를 넣어준다.
이러면 초기세팅은 끝났다!
이제 코드를 작성해준다!
onOpenURL 추가
카카오로그인 때처럼 추가를 해줘야 한다.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
// ...
.onOpenURL { url in
GIDSignIn.sharedInstance.handle(url)
}
}
}
}
결국 URL 스키마 설정과 onOpenURL 추가는 모두 딥링크 처리를 위한 작업이다.
URL 스키마는 앱 외부에서 특정 화면으로 이동하거나, 소셜 로그인 후 앱으로 돌아오는 경로를 지정하는 딥링크 방식인 것.
onOpenURL 은 해당 URL를 감지하고 알맞은 화면이나 로직을 실행해준다.
두 가지 설정을 통해 앱이 외부에서 전달된 URL을 통해 원하는 화면으로 이동하도록 돕는 핵심 요소이다 ~
GoogleLoginAdapter
final class GoogleLoginAdapter: SocialLoginService {
@MainActor
func login() async throws -> UserInfo {
return try await withCheckedThrowingContinuation { continuation in
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let presentingViewController = windowScene.windows.first?.rootViewController else {
continuation.resume(throwing: AuthError.loginFailed(service: .google))
return
}
GIDSignIn.sharedInstance.signIn(withPresenting: presentingViewController) { signInResult, error in
if let error = error {
print("==== Google Login Error ====")
print("Error: \(error.localizedDescription)")
print("==============================")
continuation.resume(throwing: AuthError.loginFailed(service: .google))
return
}
guard let user = signInResult?.user else {
continuation.resume(throwing: AuthError.userInfoNotFound(service: .google))
return
}
let userInfo = UserInfo(
id: user.userID ?? "",
name: user.profile?.name ?? "Unknown",
email: user.profile?.email ?? "Unknown"
)
continuation.resume(returning: userInfo)
}
}
}
@MainActor
func logout() async throws {
GIDSignIn.sharedInstance.signOut()
}
func getServiceName() -> String {
return "Google Auth"
}
}
결과
확실히 초기세팅하고
어댑터만 구현해놓으면 소셜로그인을 추가하는 작업이
정말 손 쉽게 완성되는 것 같다.
GitHub - joho2022/LoginPractice
Contribute to joho2022/LoginPractice development by creating an account on GitHub.
github.com