작업 내역

백로그

로그인 기능을 구현한다.

Supabase dashboard 설정

OAuth를 사용하기 위해서 우선 Supabase DashBoard에서 설정해주어야 합니다.

Authentication > Sign In / Up 항목으로 접속해 사용할 Auth Provider를 선택합니다.

스크린샷 2025-05-02 오후 7.53.55.png

Enable Sign In with (provider) 를 활성화한 후, 앱의 번들 아이디 / 클라이언트 ID 등을 설정합니다.

스크린샷 2025-05-02 오후 7.53.40.png

idToken으로 로그인 하기

Supabase SDK를 살펴보면 idToken으로 signIn을 요청하는 로직은 아래와 같이 구성되어 있습니다.

내부적으로 email을 활용하는 signIn과 동일한 로직을 활용하고 grant_type만 id_token으로 설정해주면 되는 것을 확인할 수 있습니다.

  /// Allows signing in with an ID token issued by certain supported providers.
  /// The ID token is verified for validity and a new session is established.
  @discardableResult
  public func signInWithIdToken(credentials: OpenIDConnectCredentials) async throws -> Session {
    try await _signIn(
      request: .init(
        url: configuration.url.appendingPathComponent("token"),
        method: .post,
        query: [URLQueryItem(name: "grant_type", value: "id_token")],
        body: configuration.encoder.encode(credentials)
      )
    )
  }

파라미터로 주어진 credentials는 어떤 값을 넘겨주는지 확인해보겠습니다.

public struct OpenIDConnectCredentials: Codable, Hashable, Sendable {
  /// Provider name or OIDC `iss` value identifying which provider should be used to verify the
  /// provided token. Supported names: `google`, `apple`, `azure`, `facebook`.
  public var provider: Provider
  public var idToken: String

  /// If the ID token contains an `at_hash` claim, then the hash of this value is compared to the
  /// value in the ID token.
  public var accessToken: String?

  /// If the ID token contains a `nonce` claim, then the hash of this value is compared to the value
  /// in the ID token.
  public var nonce: String?

  /// Verification token received when the user completes the captcha on the site.
  public var gotrueMetaSecurity: AuthMetaSecurity?
// ,,, 중략 
  public enum Provider: String, Codable, Hashable, Sendable {
    case google, apple, azure, facebook
  }
}

nonce 값은 supabase dashboard에서도 확인할 수 있지만, iOS Client에서는 사용할 필요가 없습니다.

스크린샷 2025-05-11 오전 12.55.04.png