@descope/angular-sdk 0.5.10 → 0.5.11

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.
Files changed (146) hide show
  1. package/.eslintrc.json +41 -0
  2. package/.prettierrc +7 -0
  3. package/CHANGELOG.md +5 -0
  4. package/LICENSE +21 -0
  5. package/README.md +647 -11
  6. package/angular.json +154 -0
  7. package/{esm2022 → dist/esm2022}/lib/components/access-key-management/access-key-management.component.mjs +4 -4
  8. package/{esm2022 → dist/esm2022}/lib/components/audit-management/audit-management.component.mjs +4 -4
  9. package/dist/esm2022/lib/components/descope/descope.component.mjs +156 -0
  10. package/{esm2022 → dist/esm2022}/lib/components/role-management/role-management.component.mjs +4 -4
  11. package/dist/esm2022/lib/components/sign-in-flow/sign-in-flow.component.mjs +44 -0
  12. package/dist/esm2022/lib/components/sign-up-flow/sign-up-flow.component.mjs +44 -0
  13. package/dist/esm2022/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.mjs +44 -0
  14. package/{esm2022 → dist/esm2022}/lib/components/user-management/user-management.component.mjs +4 -4
  15. package/dist/esm2022/lib/components/user-profile/user-profile.component.mjs +66 -0
  16. package/{esm2022 → dist/esm2022}/lib/descope-auth.module.mjs +5 -5
  17. package/{esm2022 → dist/esm2022}/lib/services/descope-auth.guard.mjs +1 -1
  18. package/dist/esm2022/lib/services/descope-auth.service.mjs +154 -0
  19. package/dist/esm2022/lib/services/descope.interceptor.mjs +51 -0
  20. package/dist/esm2022/lib/types/types.mjs +6 -0
  21. package/{esm2022 → dist/esm2022}/lib/utils/constants.mjs +1 -1
  22. package/dist/esm2022/lib/utils/helpers.mjs +27 -0
  23. package/{fesm2022 → dist/fesm2022}/descope-angular-sdk.mjs +37 -37
  24. package/dist/fesm2022/descope-angular-sdk.mjs.map +1 -0
  25. package/{lib → dist/lib}/services/descope-auth.service.d.ts +3 -2
  26. package/jest.config.js +17 -0
  27. package/package.json +62 -19
  28. package/project.json +17 -0
  29. package/projects/angular-sdk/.eslintrc.json +32 -0
  30. package/projects/angular-sdk/ng-package.json +17 -0
  31. package/projects/angular-sdk/package.json +87 -0
  32. package/projects/angular-sdk/src/environment.ts +3 -0
  33. package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.spec.ts +84 -0
  34. package/projects/angular-sdk/src/lib/components/access-key-management/access-key-management.component.ts +63 -0
  35. package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.spec.ts +84 -0
  36. package/projects/angular-sdk/src/lib/components/audit-management/audit-management.component.ts +63 -0
  37. package/projects/angular-sdk/src/lib/components/descope/descope.component.spec.ts +142 -0
  38. package/projects/angular-sdk/src/lib/components/descope/descope.component.ts +171 -0
  39. package/projects/angular-sdk/src/lib/components/role-management/role-management.component.spec.ts +84 -0
  40. package/projects/angular-sdk/src/lib/components/role-management/role-management.component.ts +63 -0
  41. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.html +17 -0
  42. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.spec.ts +53 -0
  43. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.ts +35 -0
  44. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.html +17 -0
  45. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.spec.ts +51 -0
  46. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.ts +35 -0
  47. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.html +17 -0
  48. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.spec.ts +53 -0
  49. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.ts +35 -0
  50. package/projects/angular-sdk/src/lib/components/user-management/user-management.component.spec.ts +84 -0
  51. package/projects/angular-sdk/src/lib/components/user-management/user-management.component.ts +64 -0
  52. package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.spec.ts +93 -0
  53. package/projects/angular-sdk/src/lib/components/user-profile/user-profile.component.ts +77 -0
  54. package/projects/angular-sdk/src/lib/descope-auth.module.ts +61 -0
  55. package/projects/angular-sdk/src/lib/services/descope-auth.guard.spec.ts +76 -0
  56. package/projects/angular-sdk/src/lib/services/descope-auth.guard.ts +16 -0
  57. package/projects/angular-sdk/src/lib/services/descope-auth.service.spec.ts +309 -0
  58. package/projects/angular-sdk/src/lib/services/descope-auth.service.ts +200 -0
  59. package/projects/angular-sdk/src/lib/services/descope.interceptor.spec.ts +102 -0
  60. package/projects/angular-sdk/src/lib/services/descope.interceptor.ts +76 -0
  61. package/projects/angular-sdk/src/lib/types/types.ts +15 -0
  62. package/projects/angular-sdk/src/lib/utils/constants.ts +8 -0
  63. package/projects/angular-sdk/src/lib/utils/helpers.spec.ts +103 -0
  64. package/projects/angular-sdk/src/lib/utils/helpers.ts +36 -0
  65. package/projects/angular-sdk/src/public-api.ts +18 -0
  66. package/projects/angular-sdk/tsconfig.lib.json +12 -0
  67. package/projects/angular-sdk/tsconfig.lib.prod.json +10 -0
  68. package/projects/angular-sdk/tsconfig.spec.json +11 -0
  69. package/projects/demo-app/.eslintrc.json +31 -0
  70. package/projects/demo-app/src/app/app-routing.module.ts +33 -0
  71. package/projects/demo-app/src/app/app.component.html +3 -0
  72. package/projects/demo-app/src/app/app.component.scss +18 -0
  73. package/projects/demo-app/src/app/app.component.spec.ts +37 -0
  74. package/projects/demo-app/src/app/app.component.ts +8 -0
  75. package/projects/demo-app/src/app/app.module.ts +63 -0
  76. package/projects/demo-app/src/app/home/home.component.html +32 -0
  77. package/projects/demo-app/src/app/home/home.component.scss +15 -0
  78. package/projects/demo-app/src/app/home/home.component.spec.ts +44 -0
  79. package/projects/demo-app/src/app/home/home.component.ts +85 -0
  80. package/projects/demo-app/src/app/interceptor/auth.interceptor.ts +20 -0
  81. package/projects/demo-app/src/app/login/login.component.html +20 -0
  82. package/projects/demo-app/src/app/login/login.component.spec.ts +42 -0
  83. package/projects/demo-app/src/app/login/login.component.ts +41 -0
  84. package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.html +12 -0
  85. package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.spec.ts +36 -0
  86. package/projects/demo-app/src/app/manage-access-keys/manage-access-keys.component.ts +15 -0
  87. package/projects/demo-app/src/app/manage-audit/manage-audit.component.html +6 -0
  88. package/projects/demo-app/src/app/manage-audit/manage-audit.component.spec.ts +36 -0
  89. package/projects/demo-app/src/app/manage-audit/manage-audit.component.ts +15 -0
  90. package/projects/demo-app/src/app/manage-roles/manage-roles.component.html +6 -0
  91. package/projects/demo-app/src/app/manage-roles/manage-roles.component.spec.ts +36 -0
  92. package/projects/demo-app/src/app/manage-roles/manage-roles.component.ts +15 -0
  93. package/projects/demo-app/src/app/manage-users/manage-users.component.html +6 -0
  94. package/projects/demo-app/src/app/manage-users/manage-users.component.spec.ts +36 -0
  95. package/projects/demo-app/src/app/manage-users/manage-users.component.ts +15 -0
  96. package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.html +6 -0
  97. package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.spec.ts +36 -0
  98. package/projects/demo-app/src/app/my-user-profile/my-user-profile.component.ts +20 -0
  99. package/projects/demo-app/src/app/my-user-profile/my-user-profile.scss +18 -0
  100. package/projects/demo-app/src/app/protected/protected.component.html +18 -0
  101. package/projects/demo-app/src/app/protected/protected.component.scss +8 -0
  102. package/projects/demo-app/src/app/protected/protected.component.spec.ts +42 -0
  103. package/projects/demo-app/src/app/protected/protected.component.ts +41 -0
  104. package/projects/demo-app/src/assets/.gitkeep +0 -0
  105. package/projects/demo-app/src/environments/conifg.ts +14 -0
  106. package/projects/demo-app/src/environments/environment.ts +20 -0
  107. package/projects/demo-app/src/favicon.ico +0 -0
  108. package/projects/demo-app/src/index.html +17 -0
  109. package/projects/demo-app/src/main.ts +7 -0
  110. package/projects/demo-app/src/styles.scss +21 -0
  111. package/projects/demo-app/tsconfig.app.json +11 -0
  112. package/projects/demo-app/tsconfig.spec.json +10 -0
  113. package/scripts/setversion/setversion.js +20 -0
  114. package/setup-jest.ts +1 -0
  115. package/tsconfig.json +36 -0
  116. package/esm2022/lib/components/descope/descope.component.mjs +0 -156
  117. package/esm2022/lib/components/sign-in-flow/sign-in-flow.component.mjs +0 -44
  118. package/esm2022/lib/components/sign-up-flow/sign-up-flow.component.mjs +0 -44
  119. package/esm2022/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.mjs +0 -44
  120. package/esm2022/lib/components/user-profile/user-profile.component.mjs +0 -66
  121. package/esm2022/lib/services/descope-auth.service.mjs +0 -154
  122. package/esm2022/lib/services/descope.interceptor.mjs +0 -51
  123. package/esm2022/lib/types/types.mjs +0 -6
  124. package/esm2022/lib/utils/helpers.mjs +0 -27
  125. package/fesm2022/descope-angular-sdk.mjs.map +0 -1
  126. /package/{environment.d.ts → dist/environment.d.ts} +0 -0
  127. /package/{esm2022 → dist/esm2022}/descope-angular-sdk.mjs +0 -0
  128. /package/{esm2022 → dist/esm2022}/environment.mjs +0 -0
  129. /package/{esm2022 → dist/esm2022}/public-api.mjs +0 -0
  130. /package/{index.d.ts → dist/index.d.ts} +0 -0
  131. /package/{lib → dist/lib}/components/access-key-management/access-key-management.component.d.ts +0 -0
  132. /package/{lib → dist/lib}/components/audit-management/audit-management.component.d.ts +0 -0
  133. /package/{lib → dist/lib}/components/descope/descope.component.d.ts +0 -0
  134. /package/{lib → dist/lib}/components/role-management/role-management.component.d.ts +0 -0
  135. /package/{lib → dist/lib}/components/sign-in-flow/sign-in-flow.component.d.ts +0 -0
  136. /package/{lib → dist/lib}/components/sign-up-flow/sign-up-flow.component.d.ts +0 -0
  137. /package/{lib → dist/lib}/components/sign-up-or-in-flow/sign-up-or-in-flow.component.d.ts +0 -0
  138. /package/{lib → dist/lib}/components/user-management/user-management.component.d.ts +0 -0
  139. /package/{lib → dist/lib}/components/user-profile/user-profile.component.d.ts +0 -0
  140. /package/{lib → dist/lib}/descope-auth.module.d.ts +0 -0
  141. /package/{lib → dist/lib}/services/descope-auth.guard.d.ts +0 -0
  142. /package/{lib → dist/lib}/services/descope.interceptor.d.ts +0 -0
  143. /package/{lib → dist/lib}/types/types.d.ts +0 -0
  144. /package/{lib → dist/lib}/utils/constants.d.ts +0 -0
  145. /package/{lib → dist/lib}/utils/helpers.d.ts +0 -0
  146. /package/{public-api.d.ts → dist/public-api.d.ts} +0 -0
@@ -0,0 +1,8 @@
1
+ import { environment } from '../../environment';
2
+
3
+ export const baseHeaders = {
4
+ 'x-descope-sdk-name': 'angular',
5
+ 'x-descope-sdk-version': environment.buildVersion
6
+ };
7
+
8
+ export const isBrowser = () => typeof window !== 'undefined';
@@ -0,0 +1,103 @@
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
+ });
@@ -0,0 +1,36 @@
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
+ }
@@ -0,0 +1,18 @@
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';
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.lib.json",
4
+ "compilerOptions": {
5
+ "declarationMap": false
6
+ },
7
+ "angularCompilerOptions": {
8
+ "compilationMode": "partial"
9
+ }
10
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,33 @@
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 {}
@@ -0,0 +1,3 @@
1
+ <main>
2
+ <router-outlet></router-outlet>
3
+ </main>
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,37 @@
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
+ });
@@ -0,0 +1,8 @@
1
+ import { Component } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'app-root',
5
+ templateUrl: './app.component.html',
6
+ styleUrls: ['./app.component.scss', './my-user-profile/my-user-profile.scss']
7
+ })
8
+ export class AppComponent {}
@@ -0,0 +1,63 @@
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 {}
@@ -0,0 +1,32 @@
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>
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,44 @@
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
+ });
@@ -0,0 +1,85 @@
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
+ }
@@ -0,0 +1,20 @@
1
+ import {
2
+ HttpHandlerFn,
3
+ HttpInterceptorFn,
4
+ HttpRequest
5
+ } from '@angular/common/http';
6
+ import { inject } from '@angular/core';
7
+ import { DescopeAuthService } from '../../../../angular-sdk/src/lib/services/descope-auth.service';
8
+
9
+ export const authenticationInterceptor: HttpInterceptorFn = (
10
+ req: HttpRequest<unknown>,
11
+ next: HttpHandlerFn
12
+ ) => {
13
+ const authService = inject(DescopeAuthService);
14
+ const sessionToken = authService.getSessionToken();
15
+ const modifiedReq = req.clone({
16
+ headers: req.headers.set('Authorization', `Bearer ${sessionToken}`)
17
+ });
18
+
19
+ return next(modifiedReq);
20
+ };
@@ -0,0 +1,20 @@
1
+ <descope
2
+ (success)="onSuccess($event)"
3
+ (error)="onError($event)"
4
+ (ready)="onReady()"
5
+ [theme]="theme"
6
+ [flowId]="flowId"
7
+ [locale]="locale"
8
+ [redirectUrl]="redirectUrl"
9
+ [telemetryKey]="telemetryKey"
10
+ [tenant]="tenantId"
11
+ [debug]="debugMode"
12
+ [errorTransformer]="errorTransformer"
13
+ ></descope>
14
+ <div
15
+ *ngIf="isLoading"
16
+ class="loading-indicator"
17
+ style="display: flex; justify-content: center; align-items: center"
18
+ >
19
+ Loading...
20
+ </div>
@@ -0,0 +1,42 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { LoginComponent } from './login.component';
4
+ import createSdk from '@descope/web-js-sdk';
5
+ import { NO_ERRORS_SCHEMA } from '@angular/core';
6
+ import { DescopeAuthConfig } from '../../../../angular-sdk/src/lib/types/types';
7
+ import mocked = jest.mocked;
8
+
9
+ jest.mock('@descope/web-js-sdk');
10
+
11
+ describe('LoginComponent', () => {
12
+ let component: LoginComponent;
13
+ let fixture: ComponentFixture<LoginComponent>;
14
+
15
+ let mockedCreateSdk: jest.Mock;
16
+ const onSessionTokenChangeSpy = jest.fn();
17
+ const onUserChangeSpy = jest.fn();
18
+
19
+ beforeEach(() => {
20
+ mockedCreateSdk = mocked(createSdk);
21
+ mockedCreateSdk.mockReturnValue({
22
+ onSessionTokenChange: onSessionTokenChangeSpy,
23
+ onUserChange: onUserChangeSpy
24
+ });
25
+
26
+ TestBed.configureTestingModule({
27
+ schemas: [NO_ERRORS_SCHEMA],
28
+ declarations: [LoginComponent],
29
+ providers: [
30
+ DescopeAuthConfig,
31
+ { provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
32
+ ]
33
+ });
34
+ fixture = TestBed.createComponent(LoginComponent);
35
+ component = fixture.componentInstance;
36
+ fixture.detectChanges();
37
+ });
38
+
39
+ it('should create', () => {
40
+ expect(component).toBeTruthy();
41
+ });
42
+ });