@descope/angular-sdk 0.5.11 → 0.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/services/descope-auth.service.d.ts +0 -1
- package/package.json +21 -17
- package/.eslintrc.json +0 -41
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -5
- package/angular.json +0 -154
- package/jest.config.js +0 -17
- package/project.json +0 -17
- package/projects/angular-sdk/.eslintrc.json +0 -32
- package/projects/angular-sdk/ng-package.json +0 -17
- package/projects/angular-sdk/package.json +0 -87
- package/projects/angular-sdk/src/environment.ts +0 -3
- package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/descope/descope.component.spec.ts +0 -142
- package/projects/angular-sdk/src/lib/components/descope/descope.component.ts +0 -171
- package/projects/angular-sdk/src/lib/components/role-management/role-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/role-management/role-management.component.ts +0 -63
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.spec.ts +0 -53
- package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.spec.ts +0 -51
- package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.html +0 -17
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.spec.ts +0 -53
- package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.ts +0 -35
- package/projects/angular-sdk/src/lib/components/user-management/user-management.component.spec.ts +0 -84
- package/projects/angular-sdk/src/lib/components/user-management/user-management.component.ts +0 -64
- package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.spec.ts +0 -93
- package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.ts +0 -77
- package/projects/angular-sdk/src/lib/descope-auth.module.ts +0 -61
- package/projects/angular-sdk/src/lib/services/descope-auth.guard.spec.ts +0 -76
- package/projects/angular-sdk/src/lib/services/descope-auth.guard.ts +0 -16
- package/projects/angular-sdk/src/lib/services/descope-auth.service.spec.ts +0 -309
- package/projects/angular-sdk/src/lib/services/descope-auth.service.ts +0 -200
- package/projects/angular-sdk/src/lib/services/descope.interceptor.spec.ts +0 -102
- package/projects/angular-sdk/src/lib/services/descope.interceptor.ts +0 -76
- package/projects/angular-sdk/src/lib/types/types.ts +0 -15
- package/projects/angular-sdk/src/lib/utils/constants.ts +0 -8
- package/projects/angular-sdk/src/lib/utils/helpers.spec.ts +0 -103
- package/projects/angular-sdk/src/lib/utils/helpers.ts +0 -36
- package/projects/angular-sdk/src/public-api.ts +0 -18
- package/projects/angular-sdk/tsconfig.lib.json +0 -12
- package/projects/angular-sdk/tsconfig.lib.prod.json +0 -10
- package/projects/angular-sdk/tsconfig.spec.json +0 -11
- package/projects/demo-app/.eslintrc.json +0 -31
- package/projects/demo-app/src/app/app-routing.module.ts +0 -33
- package/projects/demo-app/src/app/app.component.html +0 -3
- package/projects/demo-app/src/app/app.component.scss +0 -18
- package/projects/demo-app/src/app/app.component.spec.ts +0 -37
- package/projects/demo-app/src/app/app.component.ts +0 -8
- package/projects/demo-app/src/app/app.module.ts +0 -63
- package/projects/demo-app/src/app/home/home.component.html +0 -32
- package/projects/demo-app/src/app/home/home.component.scss +0 -15
- package/projects/demo-app/src/app/home/home.component.spec.ts +0 -44
- package/projects/demo-app/src/app/home/home.component.ts +0 -85
- package/projects/demo-app/src/app/interceptor/auth.interceptor.ts +0 -20
- package/projects/demo-app/src/app/login/login.component.html +0 -20
- package/projects/demo-app/src/app/login/login.component.spec.ts +0 -42
- package/projects/demo-app/src/app/login/login.component.ts +0 -41
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.html +0 -12
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.ts +0 -15
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.html +0 -6
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-audit/manage-audit.component.ts +0 -15
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.html +0 -6
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-roles/manage-roles.component.ts +0 -15
- package/projects/demo-app/src/app/manage-users/manage-users.component.html +0 -6
- package/projects/demo-app/src/app/manage-users/manage-users.component.spec.ts +0 -36
- package/projects/demo-app/src/app/manage-users/manage-users.component.ts +0 -15
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.html +0 -6
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.spec.ts +0 -36
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.ts +0 -20
- package/projects/demo-app/src/app/my-user-profile/my-user-profile.scss +0 -18
- package/projects/demo-app/src/app/protected/protected.component.html +0 -18
- package/projects/demo-app/src/app/protected/protected.component.scss +0 -8
- package/projects/demo-app/src/app/protected/protected.component.spec.ts +0 -42
- package/projects/demo-app/src/app/protected/protected.component.ts +0 -41
- package/projects/demo-app/src/assets/.gitkeep +0 -0
- package/projects/demo-app/src/environments/conifg.ts +0 -14
- package/projects/demo-app/src/environments/environment.ts +0 -20
- package/projects/demo-app/src/favicon.ico +0 -0
- package/projects/demo-app/src/index.html +0 -17
- package/projects/demo-app/src/main.ts +0 -7
- package/projects/demo-app/src/styles.scss +0 -21
- package/projects/demo-app/tsconfig.app.json +0 -11
- package/projects/demo-app/tsconfig.spec.json +0 -10
- package/scripts/setversion/setversion.js +0 -20
- package/setup-jest.ts +0 -1
- package/tsconfig.json +0 -36
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { inject } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
HttpErrorResponse,
|
|
4
|
-
HttpHandlerFn,
|
|
5
|
-
HttpInterceptorFn,
|
|
6
|
-
HttpRequest
|
|
7
|
-
} from '@angular/common/http';
|
|
8
|
-
import { throwError } from 'rxjs';
|
|
9
|
-
import { catchError, switchMap } from 'rxjs/operators';
|
|
10
|
-
import { DescopeAuthService } from './descope-auth.service';
|
|
11
|
-
import { DescopeAuthConfig } from '../types/types';
|
|
12
|
-
|
|
13
|
-
export const descopeInterceptor: HttpInterceptorFn = (request, next) => {
|
|
14
|
-
const config = inject(DescopeAuthConfig);
|
|
15
|
-
const authService = inject(DescopeAuthService);
|
|
16
|
-
|
|
17
|
-
function refreshAndRetry(
|
|
18
|
-
request: HttpRequest<unknown>,
|
|
19
|
-
next: HttpHandlerFn,
|
|
20
|
-
error?: HttpErrorResponse
|
|
21
|
-
) {
|
|
22
|
-
return authService.refreshSession().pipe(
|
|
23
|
-
switchMap((refreshed) => {
|
|
24
|
-
if (refreshed.ok && refreshed.data) {
|
|
25
|
-
const requestWithRefreshedToken = addTokenToRequest(
|
|
26
|
-
request,
|
|
27
|
-
refreshed.data?.sessionJwt
|
|
28
|
-
);
|
|
29
|
-
return next(requestWithRefreshedToken);
|
|
30
|
-
} else {
|
|
31
|
-
return throwError(
|
|
32
|
-
() => error ?? new Error('Could not refresh session!')
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function shouldIntercept(request: HttpRequest<unknown>): boolean {
|
|
40
|
-
return (
|
|
41
|
-
(config.pathsToIntercept?.length === 0 ||
|
|
42
|
-
config.pathsToIntercept?.some((path) => request.url.includes(path))) ??
|
|
43
|
-
true
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function addTokenToRequest(
|
|
48
|
-
request: HttpRequest<unknown>,
|
|
49
|
-
token: string
|
|
50
|
-
): HttpRequest<unknown> {
|
|
51
|
-
return request.clone({
|
|
52
|
-
setHeaders: {
|
|
53
|
-
Authorization: `Bearer ${token}`
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (shouldIntercept(request)) {
|
|
59
|
-
const token = authService.getSessionToken();
|
|
60
|
-
if (!token) {
|
|
61
|
-
return refreshAndRetry(request, next);
|
|
62
|
-
}
|
|
63
|
-
const requestWithToken = addTokenToRequest(request, token);
|
|
64
|
-
return next(requestWithToken).pipe(
|
|
65
|
-
catchError((error: HttpErrorResponse) => {
|
|
66
|
-
if (error.status === 401 || error.status === 403) {
|
|
67
|
-
return refreshAndRetry(request, next, error);
|
|
68
|
-
} else {
|
|
69
|
-
return throwError(() => error);
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
return next(request);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@descope/web-component';
|
|
2
|
-
|
|
3
|
-
export class DescopeAuthConfig {
|
|
4
|
-
projectId = '';
|
|
5
|
-
baseUrl?: string;
|
|
6
|
-
baseStaticUrl?: string;
|
|
7
|
-
// If true, tokens will be stored on local storage
|
|
8
|
-
persistTokens?: boolean;
|
|
9
|
-
sessionTokenViaCookie?: boolean;
|
|
10
|
-
// If true, last authenticated user will be stored on local storage and can accessed with getUser function
|
|
11
|
-
storeLastAuthenticatedUser?: boolean;
|
|
12
|
-
pathsToIntercept?: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type { ILogger };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { observabilify, Observablefied } from './helpers';
|
|
2
|
-
import { lastValueFrom, Observable } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
describe('Helpers', () => {
|
|
5
|
-
describe('Observabilify', () => {
|
|
6
|
-
it('should not affect simple object', () => {
|
|
7
|
-
//GIVEN
|
|
8
|
-
const obj = {
|
|
9
|
-
field1: 'string',
|
|
10
|
-
field2: 123,
|
|
11
|
-
nested: {
|
|
12
|
-
field1: 'string',
|
|
13
|
-
field2: 123
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
type TestType = typeof obj;
|
|
17
|
-
|
|
18
|
-
//WHEN
|
|
19
|
-
const result: Observablefied<TestType> = observabilify<TestType>(obj);
|
|
20
|
-
|
|
21
|
-
//THEN
|
|
22
|
-
expect(result).toStrictEqual(obj);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should not affect simple object with non async functions', () => {
|
|
26
|
-
//GIVEN
|
|
27
|
-
const obj = {
|
|
28
|
-
field1: 'string',
|
|
29
|
-
field2: 123,
|
|
30
|
-
fn: (arg1: string, arg2: number): string => {
|
|
31
|
-
return arg1 + arg2.toString();
|
|
32
|
-
},
|
|
33
|
-
nested: {
|
|
34
|
-
fn2: (arg: string): string => {
|
|
35
|
-
return arg;
|
|
36
|
-
},
|
|
37
|
-
field1: 'string',
|
|
38
|
-
field2: 123
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
type TestType = typeof obj;
|
|
42
|
-
const expected1 = obj.fn('Test', 1);
|
|
43
|
-
const expected2 = obj.nested.fn2('Test');
|
|
44
|
-
|
|
45
|
-
//WHEN
|
|
46
|
-
const transformed: Observablefied<TestType> =
|
|
47
|
-
observabilify<TestType>(obj);
|
|
48
|
-
const actual1 = transformed.fn('Test', 1);
|
|
49
|
-
const actual2 = transformed.nested.fn2('Test');
|
|
50
|
-
|
|
51
|
-
//THEN
|
|
52
|
-
expect(expected1).toStrictEqual(actual1);
|
|
53
|
-
expect(expected2).toStrictEqual(actual2);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should transform async functions', async () => {
|
|
57
|
-
//GIVEN
|
|
58
|
-
const obj = {
|
|
59
|
-
field1: 'string',
|
|
60
|
-
field2: 123,
|
|
61
|
-
fn: (arg1: string, arg2: number): string => {
|
|
62
|
-
return arg1 + arg2.toString();
|
|
63
|
-
},
|
|
64
|
-
asyncFn: (arg1: string, arg2: number): Promise<string> => {
|
|
65
|
-
return Promise.resolve(arg1 + arg2.toString());
|
|
66
|
-
},
|
|
67
|
-
nested: {
|
|
68
|
-
fn2: (arg: string) => {
|
|
69
|
-
return arg;
|
|
70
|
-
},
|
|
71
|
-
asyncFn: (arg: string): Promise<string> => {
|
|
72
|
-
return Promise.resolve(arg);
|
|
73
|
-
},
|
|
74
|
-
field1: 'string',
|
|
75
|
-
field2: 123
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
type TestType = typeof obj;
|
|
79
|
-
const expected1 = obj.fn('Test', 1);
|
|
80
|
-
const expected2 = obj.nested.fn2('Test');
|
|
81
|
-
const expected3 = await obj.asyncFn('Test', 1);
|
|
82
|
-
const expected4 = await obj.nested.asyncFn('Test');
|
|
83
|
-
|
|
84
|
-
//WHEN
|
|
85
|
-
const transformed: Observablefied<TestType> =
|
|
86
|
-
observabilify<TestType>(obj);
|
|
87
|
-
const actual1 = transformed.fn('Test', 1);
|
|
88
|
-
const actual2 = transformed.nested.fn2('Test');
|
|
89
|
-
const actual3Async = transformed.asyncFn('Test', 1);
|
|
90
|
-
const actual3 = await lastValueFrom(actual3Async);
|
|
91
|
-
const actual4Async = transformed.nested.asyncFn('Test');
|
|
92
|
-
const actual4 = await lastValueFrom(actual4Async);
|
|
93
|
-
|
|
94
|
-
//THEN
|
|
95
|
-
expect(expected1).toStrictEqual(actual1);
|
|
96
|
-
expect(expected2).toStrictEqual(actual2);
|
|
97
|
-
expect(actual3Async).toBeInstanceOf(Observable);
|
|
98
|
-
expect(actual4Async).toBeInstanceOf(Observable);
|
|
99
|
-
expect(expected3).toStrictEqual(actual3);
|
|
100
|
-
expect(expected4).toStrictEqual(actual4);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { from, Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
export type Observablefied<T> = {
|
|
4
|
-
[K in keyof T]: T[K] extends (...args: infer Args) => Promise<infer R>
|
|
5
|
-
? (...args: Args) => Observable<R>
|
|
6
|
-
: T[K] extends (...args: infer Args) => infer R
|
|
7
|
-
? (...args: Args) => R
|
|
8
|
-
: T[K] extends object
|
|
9
|
-
? Observablefied<T[K]>
|
|
10
|
-
: T[K];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function observabilify<T>(value: T): Observablefied<T> {
|
|
14
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
15
|
-
const observableValue: any = {};
|
|
16
|
-
|
|
17
|
-
for (const key in value) {
|
|
18
|
-
if (typeof value[key] === 'function') {
|
|
19
|
-
const fn = value[key] as (...args: unknown[]) => unknown;
|
|
20
|
-
observableValue[key] = (...args: unknown[]) => {
|
|
21
|
-
const fnResult = fn(...args);
|
|
22
|
-
if (fnResult instanceof Promise) {
|
|
23
|
-
return from(fnResult);
|
|
24
|
-
} else {
|
|
25
|
-
return fnResult;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
} else if (typeof value[key] === 'object' && value[key] !== null) {
|
|
29
|
-
observableValue[key] = observabilify(value[key]);
|
|
30
|
-
} else {
|
|
31
|
-
observableValue[key] = value[key];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return observableValue as Observablefied<T>;
|
|
36
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Public API Surface of angular-sdk
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from './lib/services/descope-auth.service';
|
|
6
|
-
export * from './lib/services/descope-auth.guard';
|
|
7
|
-
export * from './lib/services/descope.interceptor';
|
|
8
|
-
export * from './lib/descope-auth.module';
|
|
9
|
-
export * from './lib/components/descope/descope.component';
|
|
10
|
-
export * from './lib/components/sign-in-flow/sign-in-flow.component';
|
|
11
|
-
export * from './lib/components/sign-up-flow/sign-up-flow.component';
|
|
12
|
-
export * from './lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component';
|
|
13
|
-
export * from './lib/components/user-management/user-management.component';
|
|
14
|
-
export * from './lib/components/role-management/role-management.component';
|
|
15
|
-
export * from './lib/components/access-key-management/access-key-management.component';
|
|
16
|
-
export * from './lib/components/audit-management/audit-management.component';
|
|
17
|
-
export * from './lib/components/user-profile/user-profile.component';
|
|
18
|
-
export * from './lib/types/types';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"types": []
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["**/*.spec.ts"]
|
|
12
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/spec",
|
|
6
|
-
"types": ["jest"],
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"emitDecoratorMetadata": true
|
|
9
|
-
},
|
|
10
|
-
"include": ["**/*.spec.ts", "**/*.d.ts"]
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../.eslintrc.json",
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts"],
|
|
7
|
-
"rules": {
|
|
8
|
-
"@angular-eslint/directive-selector": [
|
|
9
|
-
"error",
|
|
10
|
-
{
|
|
11
|
-
"type": "attribute",
|
|
12
|
-
"prefix": "app",
|
|
13
|
-
"style": "camelCase"
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"@angular-eslint/component-selector": [
|
|
17
|
-
"error",
|
|
18
|
-
{
|
|
19
|
-
"type": "element",
|
|
20
|
-
"prefix": "app",
|
|
21
|
-
"style": "kebab-case"
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"files": ["*.html"],
|
|
28
|
-
"rules": {}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { NgModule } from '@angular/core';
|
|
2
|
-
import { RouterModule, Routes } from '@angular/router';
|
|
3
|
-
import { HomeComponent } from './home/home.component';
|
|
4
|
-
import { ProtectedComponent } from './protected/protected.component';
|
|
5
|
-
import { descopeAuthGuard } from '../../../angular-sdk/src/lib/services/descope-auth.guard';
|
|
6
|
-
import { LoginComponent } from './login/login.component';
|
|
7
|
-
import { ManageUsersComponent } from './manage-users/manage-users.component';
|
|
8
|
-
import { ManageRolesComponent } from './manage-roles/manage-roles.component';
|
|
9
|
-
import { ManageAccessKeysComponent } from './manage-access-keys/manage-access-keys.component';
|
|
10
|
-
import { ManageAuditComponent } from './manage-audit/manage-audit.component';
|
|
11
|
-
import { MyUserProfileComponent } from './my-user-profile/my-user-profile.component';
|
|
12
|
-
|
|
13
|
-
const routes: Routes = [
|
|
14
|
-
{
|
|
15
|
-
path: 'step-up',
|
|
16
|
-
component: ProtectedComponent,
|
|
17
|
-
canActivate: [descopeAuthGuard],
|
|
18
|
-
data: { descopeFallbackUrl: '/' }
|
|
19
|
-
},
|
|
20
|
-
{ path: 'login', component: LoginComponent },
|
|
21
|
-
{ path: 'manage-users', component: ManageUsersComponent },
|
|
22
|
-
{ path: 'manage-roles', component: ManageRolesComponent },
|
|
23
|
-
{ path: 'manage-access-keys', component: ManageAccessKeysComponent },
|
|
24
|
-
{ path: 'manage-audit', component: ManageAuditComponent },
|
|
25
|
-
{ path: 'my-user-profile', component: MyUserProfileComponent },
|
|
26
|
-
{ path: '**', component: HomeComponent }
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
@NgModule({
|
|
30
|
-
imports: [RouterModule.forRoot(routes, { enableTracing: false })],
|
|
31
|
-
exports: [RouterModule]
|
|
32
|
-
})
|
|
33
|
-
export class AppRoutingModule {}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
height: 100vh;
|
|
3
|
-
position: relative;
|
|
4
|
-
}
|
|
5
|
-
main {
|
|
6
|
-
border-radius: 10px;
|
|
7
|
-
margin: auto;
|
|
8
|
-
border: 1px solid lightgray;
|
|
9
|
-
padding: 20px;
|
|
10
|
-
max-width: 500px;
|
|
11
|
-
box-shadow:
|
|
12
|
-
13px 13px 20px #cbced1,
|
|
13
|
-
-13px -13px 20px #fff;
|
|
14
|
-
background: #ecf0f3;
|
|
15
|
-
position: relative;
|
|
16
|
-
top: 50%;
|
|
17
|
-
transform: translateY(-50%);
|
|
18
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { RouterTestingModule } from '@angular/router/testing';
|
|
3
|
-
import { AppComponent } from './app.component';
|
|
4
|
-
import createSdk from '@descope/web-js-sdk';
|
|
5
|
-
import mocked = jest.mocked;
|
|
6
|
-
import { DescopeAuthConfig } from '../../../angular-sdk/src/lib/types/types';
|
|
7
|
-
|
|
8
|
-
jest.mock('@descope/web-js-sdk');
|
|
9
|
-
|
|
10
|
-
describe('AppComponent', () => {
|
|
11
|
-
let mockedCreateSdk: jest.Mock;
|
|
12
|
-
const onSessionTokenChangeSpy = jest.fn();
|
|
13
|
-
const onUserChangeSpy = jest.fn();
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
mockedCreateSdk = mocked(createSdk);
|
|
17
|
-
mockedCreateSdk.mockReturnValue({
|
|
18
|
-
onSessionTokenChange: onSessionTokenChangeSpy,
|
|
19
|
-
onUserChange: onUserChangeSpy
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
TestBed.configureTestingModule({
|
|
23
|
-
imports: [RouterTestingModule],
|
|
24
|
-
providers: [
|
|
25
|
-
DescopeAuthConfig,
|
|
26
|
-
{ provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
|
|
27
|
-
],
|
|
28
|
-
declarations: [AppComponent]
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should create the app', () => {
|
|
33
|
-
const fixture = TestBed.createComponent(AppComponent);
|
|
34
|
-
const app = fixture.componentInstance;
|
|
35
|
-
expect(app).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
|
2
|
-
import { BrowserModule } from '@angular/platform-browser';
|
|
3
|
-
|
|
4
|
-
import { AppRoutingModule } from './app-routing.module';
|
|
5
|
-
import { AppComponent } from './app.component';
|
|
6
|
-
import { DescopeAuthModule } from '../../../angular-sdk/src/lib/descope-auth.module';
|
|
7
|
-
import { HomeComponent } from './home/home.component';
|
|
8
|
-
import { ProtectedComponent } from './protected/protected.component';
|
|
9
|
-
import { environment } from '../environments/environment';
|
|
10
|
-
import { DescopeAuthService } from 'projects/angular-sdk/src/public-api';
|
|
11
|
-
import { zip } from 'rxjs';
|
|
12
|
-
import { LoginComponent } from './login/login.component';
|
|
13
|
-
import { ManageUsersComponent } from './manage-users/manage-users.component';
|
|
14
|
-
import { ManageRolesComponent } from './manage-roles/manage-roles.component';
|
|
15
|
-
import { ManageAccessKeysComponent } from './manage-access-keys/manage-access-keys.component';
|
|
16
|
-
import { ManageAuditComponent } from './manage-audit/manage-audit.component';
|
|
17
|
-
import { MyUserProfileComponent } from './my-user-profile/my-user-profile.component';
|
|
18
|
-
import {
|
|
19
|
-
HttpClientModule,
|
|
20
|
-
provideHttpClient,
|
|
21
|
-
withInterceptors
|
|
22
|
-
} from '@angular/common/http';
|
|
23
|
-
import { descopeInterceptor } from '../../../angular-sdk/src/lib/services/descope.interceptor';
|
|
24
|
-
|
|
25
|
-
export function initializeApp(authService: DescopeAuthService) {
|
|
26
|
-
return () => zip([authService.refreshSession(), authService.refreshUser()]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@NgModule({
|
|
30
|
-
declarations: [
|
|
31
|
-
AppComponent,
|
|
32
|
-
HomeComponent,
|
|
33
|
-
ProtectedComponent,
|
|
34
|
-
LoginComponent,
|
|
35
|
-
ManageUsersComponent,
|
|
36
|
-
ManageRolesComponent,
|
|
37
|
-
ManageAccessKeysComponent,
|
|
38
|
-
ManageAuditComponent,
|
|
39
|
-
MyUserProfileComponent
|
|
40
|
-
],
|
|
41
|
-
imports: [
|
|
42
|
-
BrowserModule,
|
|
43
|
-
AppRoutingModule,
|
|
44
|
-
HttpClientModule,
|
|
45
|
-
DescopeAuthModule.forRoot({
|
|
46
|
-
projectId: environment.descopeProjectId,
|
|
47
|
-
baseUrl: environment.descopeBaseUrl || '',
|
|
48
|
-
baseStaticUrl: environment.descopeBaseStaticUrl || '',
|
|
49
|
-
sessionTokenViaCookie: true
|
|
50
|
-
})
|
|
51
|
-
],
|
|
52
|
-
providers: [
|
|
53
|
-
{
|
|
54
|
-
provide: APP_INITIALIZER,
|
|
55
|
-
useFactory: initializeApp,
|
|
56
|
-
deps: [DescopeAuthService],
|
|
57
|
-
multi: true
|
|
58
|
-
},
|
|
59
|
-
provideHttpClient(withInterceptors([descopeInterceptor]))
|
|
60
|
-
],
|
|
61
|
-
bootstrap: [AppComponent]
|
|
62
|
-
})
|
|
63
|
-
export class AppModule {}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<h2>ANGULAR SDK DEMO APP</h2>
|
|
2
|
-
<button *ngIf="!isAuthenticated" (click)="login()">LOGIN</button>
|
|
3
|
-
<ng-container *ngIf="isAuthenticated">
|
|
4
|
-
<h3>Hello {{ userName }}</h3>
|
|
5
|
-
<div>
|
|
6
|
-
Roles:
|
|
7
|
-
<ng-container *ngIf="roles && roles.length; else noRoles">
|
|
8
|
-
{{ roles }}
|
|
9
|
-
</ng-container>
|
|
10
|
-
<ng-template #noRoles>N/A</ng-template>
|
|
11
|
-
</div>
|
|
12
|
-
<button
|
|
13
|
-
*ngIf="backendUrl.length > 0"
|
|
14
|
-
class="action-button"
|
|
15
|
-
(click)="fetchData()"
|
|
16
|
-
>
|
|
17
|
-
FETCH DATA
|
|
18
|
-
</button>
|
|
19
|
-
<button *ngIf="stepUpConfigured" class="action-button" (click)="stepUp()">
|
|
20
|
-
STEP UP
|
|
21
|
-
</button>
|
|
22
|
-
<button class="action-button" (click)="manageUsers()">Manage Users</button>
|
|
23
|
-
<button class="action-button" (click)="manageRoles()">Manage Roles</button>
|
|
24
|
-
<button class="action-button" (click)="manageAccessKeys()">
|
|
25
|
-
Manage Access Keys
|
|
26
|
-
</button>
|
|
27
|
-
<button class="action-button" (click)="manageAudit()">Manage Audit</button>
|
|
28
|
-
<button class="action-button" (click)="myUserProfile()">
|
|
29
|
-
My User Profile
|
|
30
|
-
</button>
|
|
31
|
-
<button class="logout-button" (click)="logout()">LOGOUT</button>
|
|
32
|
-
</ng-container>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
display: flex;
|
|
3
|
-
justify-content: center;
|
|
4
|
-
align-items: center;
|
|
5
|
-
flex-direction: column;
|
|
6
|
-
}
|
|
7
|
-
.action-button {
|
|
8
|
-
border: 1px solid #00ace1;
|
|
9
|
-
background-color: white;
|
|
10
|
-
color: #00ace1;
|
|
11
|
-
margin-bottom: 1rem;
|
|
12
|
-
&:first-of-type {
|
|
13
|
-
margin-top: 1rem;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { HomeComponent } from './home.component';
|
|
4
|
-
import createSdk from '@descope/web-js-sdk';
|
|
5
|
-
import mocked = jest.mocked;
|
|
6
|
-
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
|
7
|
-
import { DescopeAuthConfig } from '../../../../angular-sdk/src/lib/types/types';
|
|
8
|
-
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
|
9
|
-
|
|
10
|
-
jest.mock('@descope/web-js-sdk');
|
|
11
|
-
|
|
12
|
-
describe('HomeComponent', () => {
|
|
13
|
-
let component: HomeComponent;
|
|
14
|
-
let fixture: ComponentFixture<HomeComponent>;
|
|
15
|
-
|
|
16
|
-
let mockedCreateSdk: jest.Mock;
|
|
17
|
-
const onSessionTokenChangeSpy = jest.fn();
|
|
18
|
-
const onUserChangeSpy = jest.fn();
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
mockedCreateSdk = mocked(createSdk);
|
|
22
|
-
mockedCreateSdk.mockReturnValue({
|
|
23
|
-
onSessionTokenChange: onSessionTokenChangeSpy,
|
|
24
|
-
onUserChange: onUserChangeSpy
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
TestBed.configureTestingModule({
|
|
28
|
-
imports: [HttpClientTestingModule],
|
|
29
|
-
schemas: [NO_ERRORS_SCHEMA],
|
|
30
|
-
declarations: [HomeComponent],
|
|
31
|
-
providers: [
|
|
32
|
-
DescopeAuthConfig,
|
|
33
|
-
{ provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
|
|
34
|
-
]
|
|
35
|
-
});
|
|
36
|
-
fixture = TestBed.createComponent(HomeComponent);
|
|
37
|
-
component = fixture.componentInstance;
|
|
38
|
-
fixture.detectChanges();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should create', () => {
|
|
42
|
-
expect(component).toBeTruthy();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Component, OnInit } from '@angular/core';
|
|
2
|
-
import { DescopeAuthService } from '../../../../angular-sdk/src/lib/services/descope-auth.service';
|
|
3
|
-
import { Router } from '@angular/router';
|
|
4
|
-
import { environment } from '../../environments/environment';
|
|
5
|
-
import { HttpClient } from '@angular/common/http';
|
|
6
|
-
|
|
7
|
-
@Component({
|
|
8
|
-
selector: 'app-home',
|
|
9
|
-
templateUrl: './home.component.html',
|
|
10
|
-
styleUrls: ['./home.component.scss']
|
|
11
|
-
})
|
|
12
|
-
export class HomeComponent implements OnInit {
|
|
13
|
-
projectId: string = environment.descopeProjectId;
|
|
14
|
-
isAuthenticated: boolean = false;
|
|
15
|
-
roles: string[] = [];
|
|
16
|
-
userName: string = '';
|
|
17
|
-
stepUpConfigured = (environment.descopeStepUpFlowId ?? '').length > 0;
|
|
18
|
-
backendUrl = environment.backendUrl ?? '';
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
private router: Router,
|
|
22
|
-
private httpClient: HttpClient,
|
|
23
|
-
private authService: DescopeAuthService
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
ngOnInit() {
|
|
27
|
-
this.authService.session$.subscribe((session) => {
|
|
28
|
-
this.isAuthenticated = session.isAuthenticated;
|
|
29
|
-
if (session.sessionToken) {
|
|
30
|
-
this.roles = this.authService.getJwtRoles(session.sessionToken);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
this.authService.user$.subscribe((descopeUser) => {
|
|
34
|
-
if (descopeUser.user) {
|
|
35
|
-
this.userName = descopeUser.user.name ?? '';
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
login() {
|
|
41
|
-
this.router.navigate(['/login']).catch((err) => console.error(err));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
logout() {
|
|
45
|
-
this.authService.descopeSdk.logout();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
fetchData() {
|
|
49
|
-
if (this.backendUrl) {
|
|
50
|
-
this.httpClient
|
|
51
|
-
.get(this.backendUrl, { responseType: 'text' })
|
|
52
|
-
.subscribe((data) => alert(data));
|
|
53
|
-
} else {
|
|
54
|
-
console.warn('Please setup backendUrl in your environment');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
stepUp() {
|
|
59
|
-
this.router.navigate(['/step-up']).catch((err) => console.error(err));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
manageUsers() {
|
|
63
|
-
this.router.navigate(['/manage-users']).catch((err) => console.error(err));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
manageRoles() {
|
|
67
|
-
this.router.navigate(['/manage-roles']).catch((err) => console.error(err));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
manageAccessKeys() {
|
|
71
|
-
this.router
|
|
72
|
-
.navigate(['/manage-access-keys'])
|
|
73
|
-
.catch((err) => console.error(err));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
manageAudit() {
|
|
77
|
-
this.router.navigate(['/manage-audit']).catch((err) => console.error(err));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
myUserProfile() {
|
|
81
|
-
this.router
|
|
82
|
-
.navigate(['/my-user-profile'])
|
|
83
|
-
.catch((err) => console.error(err));
|
|
84
|
-
}
|
|
85
|
-
}
|