Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google/ClientId #34

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: Tests

on:
push:
on:
pull_request:
types: [opened]
types: [opened, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Tests:
runs-on: macos-14-xlarge
runs-on: macos-15-xlarge
steps:
- name: Cancel previous jobs
uses: styfle/[email protected]
Expand Down
38 changes: 30 additions & 8 deletions Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ extension GoogleAuthenticator: Authenticator {
/// SignIn user.
///
/// Will asynchronously return the `Response` object on success or `Error` on error.
public func signIn(from presentingViewController: UIViewController,
hint: String? = .none,
additionalScopes: [String]? = .none) async throws -> Response {
public func signIn(
from presentingViewController: UIViewController,
clientId: String? = nil,
hint: String? = .none,
additionalScopes: [String]? = .none
) async throws -> Response {
guard !provider.hasPreviousSignIn() else {
return try await restorePreviousSignIn()
}

return try await signInUser(from: presentingViewController, hint: hint, additionalScopes: additionalScopes)
// set clientId if provided (clientId is needed when doing auth via firebase)
clientId.map { provider.configuration = .init(clientID: $0) }

return try await signInUser(
from: presentingViewController,
hint: hint,
additionalScopes: additionalScopes
)
}

/// Clears the signIn footprint and logs out the user immediatelly.
Expand All @@ -46,7 +56,11 @@ extension GoogleAuthenticator: Authenticator {
/// Boolean if given `url` should be handled.
///
/// Call this from UIApplicationDelegate’s `application:openURL:options:` method.
public func canOpenUrl(_ url: URL, application: UIApplication, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
public func canOpenUrl(
_ url: URL,
application: UIApplication,
options: [UIApplication.OpenURLOptionsKey : Any]
) -> Bool {
GIDSignIn.sharedInstance.handle(url)
}
}
Expand All @@ -66,11 +80,19 @@ private extension GoogleAuthenticator {
}
}
}

func signInUser(from presentingViewController: UIViewController, hint: String?, additionalScopes: [String]?) async throws -> Response {

func signInUser(
from presentingViewController: UIViewController,
hint: String?,
additionalScopes: [String]?
) async throws -> Response {
try await withCheckedThrowingContinuation { continuation in
provider
.signIn(withPresenting: presentingViewController, hint: hint, additionalScopes: additionalScopes) { result, error in
.signIn(
withPresenting: presentingViewController,
hint: hint,
additionalScopes: additionalScopes
) { result, error in
switch (result, error) {
case (let signInResult?, _):
continuation.resume(returning: signInResult.user.authResponse)
Expand Down