Skip to content

Commit e55a60f

Browse files
committed
feat: auth0 wip
1 parent 7530d4b commit e55a60f

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

packages/auth0/android/provider/webAuthProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class WebAuthProvider {
3737
private pkce: PKCE;
3838
private scheme: string;
3939
private ctOptions: CustomTabsOptions;
40+
private redirectPrefix: string;
4041

4142
/**
4243
* Initialize the WebAuthProvider instance with an account. Additional settings can be configured,
@@ -165,6 +166,10 @@ export class WebAuthProvider {
165166
return this;
166167
}
167168

169+
public withRedirectPrefix(prefix: string) {
170+
this.redirectPrefix = prefix;
171+
}
172+
168173
/**
169174
* Use the given connection. By default no connection is specified, so the login page will be displayed.
170175
*
@@ -237,7 +242,7 @@ export class WebAuthProvider {
237242
WebAuthProvider.managerInstance = manager;
238243

239244
const redirectUri = CallbackHelper.getCallbackUri(this.scheme, activity.getApplicationContext().getPackageName(), this.account.getDomainUrl());
240-
manager.startAuthorization(activity, redirectUri, 110);
245+
manager.startAuthorization(activity, `${this.redirectPrefix || ''}${redirectUri}`, 110);
241246
}
242247

243248
// Public methods

packages/auth0/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface WebAuthOptions {
1616
scope?: string;
1717
state?: string;
1818
parameters?: { [param: string]: string };
19+
redirectPrefix?: string;
1920
}
2021

2122
export class WebAuthException extends Error {

packages/auth0/index.android.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class Auth0 extends Auth0Common {
4949
if (options.parameters != null) {
5050
webAuth.withParameters(options.parameters);
5151
}
52+
if (options.redirectPrefix != null) {
53+
webAuth.withRedirectPrefix(options.redirectPrefix);
54+
}
5255

5356
return new Promise((resolve, reject) => {
5457
try {

packages/auth0/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface WebAuthOptions {
2929
scope?: string;
3030
state?: string;
3131
parameters?: { [param: string]: string };
32+
redirectPrefix?: string;
3233
}
3334

3435
export class WebAuthException extends Error {

packages/auth0/index.ios.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export class Auth0 extends Auth0Common {
6060
if (options.parameters != null) {
6161
auth.setParameters(options.parameters);
6262
}
63+
if (options.redirectPrefix != null) {
64+
auth.setRedirectPrefix(options.redirectPrefix);
65+
}
6366

6467
return new Promise((resolve, reject) => {
6568
try {

packages/auth0/ios/safariWebAuth.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class SafariWebAuth extends WebAuth {
3232
public responseType: ResponseType[] = [ResponseType.code];
3333
public nonce: string | undefined;
3434
private authenticationSession: boolean = true;
35+
private redirectPrefix: string | undefined;
3536

3637
public static init(clientId: string, url: NSURL, presenter: ControllerModalPresenter = new ControllerModalPresenter(), telemetry: Telemetry = new Telemetry()): SafariWebAuth {
3738
return new SafariWebAuth(clientId, url, presenter, TransactionStore.shared, telemetry);
@@ -78,6 +79,10 @@ export class SafariWebAuth extends WebAuth {
7879
return this;
7980
}
8081

82+
public setRedirectPrefix(prefix: string) {
83+
this.redirectPrefix = prefix;
84+
}
85+
8186
public setResponseType(responseType: ResponseType[]): this {
8287
this.responseType = responseType;
8388
return this;
@@ -202,7 +207,12 @@ export class SafariWebAuth extends WebAuth {
202207
const components = new NSURLComponents({ URL: this.url, resolvingAgainstBaseURL: true });
203208
if (components != null && components.URL != null) {
204209
components.scheme = this.universalLink ? 'https' : bundleIdentifier;
205-
return components.URL.URLByAppendingPathComponent('ios').URLByAppendingPathComponent(bundleIdentifier).URLByAppendingPathComponent('callback');
210+
const compUrl = components.URL.URLByAppendingPathComponent('ios').URLByAppendingPathComponent(bundleIdentifier).URLByAppendingPathComponent('callback');
211+
if (this.redirectPrefix) {
212+
return NSURL.URLWithString(`${this.redirectPrefix}${compUrl.absoluteString}`);
213+
} else {
214+
return compUrl;
215+
}
206216
} else {
207217
return undefined;
208218
}

0 commit comments

Comments
 (0)