Skip to content

Commit c794b70

Browse files
Expose methods to get just the hosted URLs (#9)
This makes it easier to set up links. Also added a method for redirecting to the SAML configuration page
1 parent f14d458 commit c794b70

2 files changed

Lines changed: 76 additions & 11 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"url": "https://github.com/PropelAuth/javascript"
77
},
8-
"version": "2.0.1",
8+
"version": "2.0.2",
99
"keywords": [
1010
"auth",
1111
"user",

‎src/client.ts‎

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ export interface IAuthClient {
3333
*/
3434
logout(redirectAfterLogout: boolean): Promise<void>
3535

36+
/**
37+
* Gets the URL for the hosted signup page.
38+
*/
39+
getSignupPageUrl(options?: RedirectToSignupOptions): string
40+
41+
/**
42+
* Gets the URL for the hosted login page.
43+
*/
44+
getLoginPageUrl(options?: RedirectToLoginOptions): string
45+
46+
/**
47+
* Gets the URL for the hosted account page.
48+
*/
49+
getAccountPageUrl(): string
50+
51+
/**
52+
* Gets the URL for the hosted organization page.
53+
* @param orgId The ID of the organization's page to load. If not specified, a random one will be used instead.
54+
*/
55+
getOrgPageUrl(orgId?: string): string
56+
57+
/**
58+
* Gets the URL for the hosted create organization page.
59+
*/
60+
getCreateOrgPageUrl(): string
61+
62+
/**
63+
* Gets the URL for the hosted SAML configuration page.
64+
*/
65+
getSetupSAMLPageUrl(orgId: string): string
66+
3667
/**
3768
* Redirects the user to the signup page.
3869
*/
@@ -59,6 +90,12 @@ export interface IAuthClient {
5990
*/
6091
redirectToCreateOrgPage(): void
6192

93+
/**
94+
* Redirects the user to the SAML configuration page.
95+
*/
96+
redirectToSetupSAMLPage(orgId: string): void
97+
98+
6299
/**
63100
* Adds an observer which is called whenever the users logs in or logs out.
64101
*/
@@ -242,38 +279,66 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
242279
}
243280
},
244281

245-
redirectToSignupPage(options?: RedirectToSignupOptions): void {
282+
getSignupPageUrl(options?: RedirectToSignupOptions): string {
246283
let qs = ""
247284
if (options && options.postSignupRedirectUrl) {
248285
const encode = window ? window.btoa : btoa;
249286
qs = new URLSearchParams({"rt": encode(options.postSignupRedirectUrl)}).toString()
250287
}
251-
window.location.href = `${clientState.authUrl}/signup?${qs}`
288+
return `${clientState.authUrl}/signup?${qs}`
252289
},
253290

254-
redirectToLoginPage(options?: RedirectToLoginOptions): void {
291+
getLoginPageUrl(options?: RedirectToLoginOptions): string {
255292
let qs = ""
256293
if (options && options.postLoginRedirectUrl) {
257294
const encode = window ? window.btoa : btoa;
258295
qs = new URLSearchParams({"rt": encode(options.postLoginRedirectUrl)}).toString()
259296
}
260-
window.location.href = `${clientState.authUrl}/login?${qs}`
297+
return `${clientState.authUrl}/login?${qs}`
261298
},
262299

263-
redirectToAccountPage(): void {
264-
window.location.href = `${clientState.authUrl}/account`
300+
getAccountPageUrl(): string {
301+
return `${clientState.authUrl}/account`
265302
},
266303

267-
redirectToOrgPage(orgId?: string): void {
304+
getOrgPageUrl(orgId?: string): string {
268305
if (orgId) {
269-
window.location.href = `${clientState.authUrl}/org?id=${orgId}`
306+
return `${clientState.authUrl}/org?id=${orgId}`
270307
} else {
271-
window.location.href = `${clientState.authUrl}/org`
308+
return `${clientState.authUrl}/org`
272309
}
273310
},
274311

312+
getCreateOrgPageUrl(): string {
313+
return `${clientState.authUrl}/create_org`
314+
},
315+
316+
getSetupSAMLPageUrl(orgId: string): string {
317+
return `${clientState.authUrl}/saml?id=${orgId}`
318+
},
319+
320+
redirectToSignupPage(options?: RedirectToSignupOptions): void {
321+
window.location.href = this.getSignupPageUrl(options)
322+
},
323+
324+
redirectToLoginPage(options?: RedirectToLoginOptions): void {
325+
window.location.href = this.getLoginPageUrl(options)
326+
},
327+
328+
redirectToAccountPage(): void {
329+
window.location.href = this.getAccountPageUrl()
330+
},
331+
332+
redirectToOrgPage(orgId?: string): void {
333+
window.location.href = this.getOrgPageUrl(orgId)
334+
},
335+
275336
redirectToCreateOrgPage(): void {
276-
window.location.href = `${clientState.authUrl}/create_org`
337+
window.location.href = this.getCreateOrgPageUrl()
338+
},
339+
340+
redirectToSetupSAMLPage(orgId: string) {
341+
window.location.href = this.getSetupSAMLPageUrl(orgId)
277342
},
278343

279344
async logout(redirectAfterLogout: boolean): Promise<void> {

0 commit comments

Comments
 (0)