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

feat(auth): add signInWithOAuth #299

Merged
merged 16 commits into from
Apr 12, 2024
Merged

feat(auth): add signInWithOAuth #299

merged 16 commits into from
Apr 12, 2024

Conversation

grdsdev
Copy link
Collaborator

@grdsdev grdsdev commented Apr 1, 2024

What kind of change does this PR introduce?

Close #257

How OAuth worked before?

Before the OAuth implementation consisted of 3 steps:

  1. Call the getOAuthSignInURL method that returned a URL type.
  2. Use the URL returned in step 1 to initiate the OAuth flow, this was up to the developer to implement, on completion of this step, it should have a result URL that contains the token/code.
  3. Use the result URL from step 2 to call session(from:) method that would parse the URL and import the session into the client.

How it works after this PR?

Everything from How OAuth worked before? is still valid in case user wants full control of the flow.

But now there are 2 convenience methods (built on top of the already existent methods).

Sign in leveraging the steps mentioned above but injecting the Step 2

let session = try await signInWithProvider(provider: .google) { url in
    let resultURL = await customFlowImplementation(url: url) // Use url for initiating the flow, some options could be implementing a web view, using `openURL` method from `UIApplication`, and manually observing for deep links.
    return resultURL // Containing #token=abc.def.ghi
}

Sign in using ASWebAuthenticationSession on the platforms that supports it (Recommended)

let session = try await signInWithProvider(provider: .google) { session in 
    // additional configuration to session object
    session.presentationContextProvider = YourCustomImplementation()
}

Other changes introduced

  • Instead of providing a redirectURL on all methods, you can pass one when initializing the client, and it will be used as the default if none is provided in the method.

@grdsdev grdsdev force-pushed the feat/auth/add-signInWithOAuth branch 2 times, most recently from ceecd44 to 3c202fa Compare April 1, 2024 20:55
@grdsdev grdsdev force-pushed the feat/auth/add-signInWithOAuth branch 2 times, most recently from aa2e37e to 9231613 Compare April 2, 2024 18:41
@grdsdev grdsdev force-pushed the feat/auth/add-signInWithOAuth branch 4 times, most recently from e49a743 to d567460 Compare April 10, 2024 18:11
@grdsdev grdsdev marked this pull request as ready for review April 10, 2024 18:30
@grdsdev grdsdev force-pushed the feat/auth/add-signInWithOAuth branch from bdc757a to eea5ae4 Compare April 11, 2024 13:21
@grdsdev grdsdev force-pushed the feat/auth/add-signInWithOAuth branch from eea5ae4 to 2afffb0 Compare April 11, 2024 13:22
Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double-check, the following code on the PR body is actually meant to be signInWithOAuth, correct?

let session = try await signInWithProvider(provider: .google) { session in
// additional configuration to session object
session.presentationContextProvider = YourCustomImplementation()
}

@grdsdev
Copy link
Collaborator Author

grdsdev commented Apr 12, 2024

Yes @dshukertjr thanks for that.

@grdsdev grdsdev merged commit 1290bcf into main Apr 12, 2024
13 checks passed
@grdsdev grdsdev deleted the feat/auth/add-signInWithOAuth branch April 12, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Auth] Add signInWithOAuth method
2 participants