Skip to content

Commit 2a970ad

Browse files
authored
feat(workos-node): Add connection to CommonAuthorizationURLOptions (#347)
1 parent 4b07e5d commit 2a970ad

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/sso/__snapshots__/sso.spec.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`SSO SSO getAuthorizationURL with a connection generates an authorize url with the connection 1`] = `"https://api.workos.dev/sso/authorize?client_id=proj_123&connection=connection_123&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code"`;
4+
35
exports[`SSO SSO getAuthorizationURL with a custom api hostname generates an authorize url with the custom api hostname 1`] = `"https://api.workos.dev/sso/authorize?client_id=proj_123&domain=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code"`;
46

57
exports[`SSO SSO getAuthorizationURL with a provider generates an authorize url with the provider 1`] = `"https://api.workos.dev/sso/authorize?client_id=proj_123&provider=Google&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code"`;
@@ -8,7 +10,7 @@ exports[`SSO SSO getAuthorizationURL with no custom api hostname generates an au
810

911
exports[`SSO SSO getAuthorizationURL with no custom api hostname with projectID instead of clientID generates an authorize url with the default api hostname 1`] = `"https://api.workos.com/sso/authorize?client_id=proj_123&domain=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code"`;
1012

11-
exports[`SSO SSO getAuthorizationURL with no domain or provider throws an error for incomplete arguments 1`] = `"Incomplete arguments. Need to specify either a 'domain' or 'provider'."`;
13+
exports[`SSO SSO getAuthorizationURL with no domain or provider throws an error for incomplete arguments 1`] = `"Incomplete arguments. Need to specify either a 'connection', 'domain', or 'provider'."`;
1214

1315
exports[`SSO SSO getAuthorizationURL with state generates an authorize url with the provided state 1`] = `"https://api.workos.com/sso/authorize?client_id=proj_123&domain=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom%20state"`;
1416

src/sso/interfaces/authorization-url-options.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
export interface CommonAuthorizationURLOptions {
2+
connection?: string;
23
domain?: string;
34
provider?: string;
45
redirectURI: string;
56
state?: string;
67
}
8+
79
export type AuthorizationURLOptions =
810
| ({
911
clientID: string;

src/sso/sso.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ describe('SSO', () => {
6363
});
6464
});
6565

66+
describe('with a connection', () => {
67+
it('generates an authorize url with the connection', () => {
68+
const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
69+
apiHostname: 'api.workos.dev',
70+
});
71+
72+
const url = workos.sso.getAuthorizationURL({
73+
connection: 'connection_123',
74+
clientID: 'proj_123',
75+
redirectURI: 'example.com/sso/workos/callback',
76+
});
77+
78+
expect(url).toMatchSnapshot();
79+
});
80+
});
81+
6682
describe('with a custom api hostname', () => {
6783
it('generates an authorize url with the custom api hostname', () => {
6884
const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {

src/sso/sso.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ export class SSO {
2525
}
2626

2727
getAuthorizationURL({
28+
connection,
2829
clientID,
2930
domain,
3031
provider,
3132
projectID,
3233
redirectURI,
3334
state,
3435
}: AuthorizationURLOptions): string {
35-
if (!domain && !provider) {
36+
if (!domain && !provider && !connection) {
3637
throw new Error(
37-
`Incomplete arguments. Need to specify either a 'domain' or 'provider'.`,
38+
`Incomplete arguments. Need to specify either a 'connection', 'domain', or 'provider'.`,
3839
);
3940
}
4041

4142
const query = queryString.stringify({
43+
connection,
4244
domain,
4345
provider,
4446
client_id: clientID ?? projectID,

0 commit comments

Comments
 (0)