Skip to content

Commit

Permalink
Google/ClientId (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Egzon Arifi <[email protected]>
  • Loading branch information
borut-t and EgzonArifi authored Dec 9, 2024
1 parent bb984d3 commit 0b0562c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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:
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

0 comments on commit 0b0562c

Please sign in to comment.