Soap
202
2021-03-15 20:14:30
1
84

구글 소셜로그인 구현시 GoogleIdTokenVerifier 사용해보신분!!


구글 공식 문서나 구글링해도 바로 적용할 수 있는 코드가 잘 안나와서 어렵네요 ㅠㅠ


혹시 사용해보신분 중에 참조할만한 링크있으면 공유부탁드립니다 ㅠㅠ

0
  • 답변 1

  • BartShin
    118
    2021-03-15 22:34:58

    제가 해봤었어여 

    깃허브 주소입니다 

    https://github.com/bartshin/ScheduleManager/blob/master/ScheduleManager/GoogleCalendar/OAuth/GoogleOAuthConfig.swift

    private struct PKCE {
            let codeVerifier: String
            let codeChallenage: String
            let codeChallengeMethod = "S256"
            let state: String
            static func trim(_ str: String) -> String {
                str.replacingOccurrences(of: "+", with: "-")
                    .replacingOccurrences(of: "/", with: "_")
                    .replacingOccurrences(of: "=", with: "")
                    .trimmingCharacters(in: .whitespaces)
            }
            init() {
                var buffer = [UInt8](repeating: 0, count: 32)
    
                _ = SecRandomCopyBytes(kSecRandomDefault, buffer.count, &buffer)
    
                codeVerifier = PKCE.trim(Data(buffer).base64EncodedString())
                guard let data = codeVerifier.data(using: .ascii) else { fatalError("Fail to create PKCE instance") }
                buffer = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
                data.withUnsafeBytes {
                    _ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &buffer)
                }
                let hash = Data(buffer)
                codeChallenage = PKCE.trim(hash.base64EncodedString())
                buffer = [UInt8](repeating: 0, count: 32)
                _ = SecRandomCopyBytes(kSecRandomDefault, buffer.count, &buffer)
                state = PKCE.trim(Data(buffer).base64EncodedString())
            }
        }


  • 로그인을 하시면 답변을 등록할 수 있습니다.