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: Support for OAuth callback proxy #466

Open
wants to merge 1 commit into
base: rc
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export default class GoTrueClient {
return this._handleProviderSignIn(credentials.provider, {
redirectTo: credentials.options?.redirectTo,
scopes: credentials.options?.scopes,
proxy: credentials.options?.proxy,
queryParams: credentials.options?.queryParams,
})
}
Expand Down Expand Up @@ -750,12 +751,14 @@ export default class GoTrueClient {
options: {
redirectTo?: string
scopes?: string
proxy?: string
queryParams?: { [key: string]: string }
} = {}
) {
const url: string = this._getUrlForProvider(provider, {
redirectTo: options.redirectTo,
scopes: options.scopes,
proxy: options.proxy,
queryParams: options.queryParams,
})
// try to open on the browser
Expand Down Expand Up @@ -945,13 +948,15 @@ export default class GoTrueClient {
* Generates the relevant login URL for a third-party provider.
* @param options.redirectTo A URL or mobile address to send the user to after they are confirmed.
* @param options.scopes A space-separated list of scopes granted to the OAuth application.
* @param options.proxy A custom OAuth callback URL. The proxy must redirect (with query params retained) to the Authorize end-point
* @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application.
*/
private _getUrlForProvider(
provider: Provider,
options: {
redirectTo?: string
scopes?: string
proxy?: string
queryParams?: { [key: string]: string }
}
) {
Expand All @@ -962,6 +967,9 @@ export default class GoTrueClient {
if (options?.scopes) {
urlParams.push(`scopes=${encodeURIComponent(options.scopes)}`)
}
if (options?.proxy) {
urlParams.push(`proxy=${encodeURIComponent(options.proxy)}`)
}
if (options?.queryParams) {
const query = new URLSearchParams(options.queryParams)
urlParams.push(query.toString())
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ export type SignInWithOAuthCredentials = {
redirectTo?: string
/** A space-separated list of scopes granted to the OAuth application. */
scopes?: string
/** A custom OAuth callback URL. The proxy must redirect (with query params retained) to the Authorize end-point */
proxy?: string,
Comment on lines +350 to +351
Copy link
Contributor

Choose a reason for hiding this comment

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

As I voiced in the GoTrue PR, I believe there's a better name for proxy. Something along the lines of redirect_via or redirect_through probably conveys meaning better, but I'm open to any other name.

/** An object of query params */
queryParams?: { [key: string]: string }
}
Expand Down