@descope/angular-sdk 0.0.0-next-32627c0f-20231228 → 0.0.0-next-cc7eda17-20231228

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 (82) hide show
  1. package/.editorconfig +16 -0
  2. package/.eslintrc.json +40 -0
  3. package/.github/workflows/ci.yml +98 -0
  4. package/.github/workflows/publish-next.yml +43 -0
  5. package/.github/workflows/publish.yml +31 -0
  6. package/.github/workflows/release.yml +41 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.prettierrc +8 -0
  9. package/.vscode/extensions.json +4 -0
  10. package/.vscode/launch.json +20 -0
  11. package/.vscode/settings.json +3 -0
  12. package/.vscode/tasks.json +42 -0
  13. package/LICENSE +21 -0
  14. package/README.md +448 -13
  15. package/angular.json +154 -0
  16. package/jest.config.js +17 -0
  17. package/package.json +77 -41
  18. package/projects/angular-sdk/.eslintrc.json +32 -0
  19. package/projects/angular-sdk/README.md +21 -0
  20. package/projects/angular-sdk/ng-package.json +8 -0
  21. package/projects/angular-sdk/src/environment.ts +3 -0
  22. package/projects/angular-sdk/src/lib/components/descope/descope.component.spec.ts +104 -0
  23. package/projects/angular-sdk/src/lib/components/descope/descope.component.ts +114 -0
  24. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.html +15 -0
  25. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.spec.ts +53 -0
  26. package/projects/angular-sdk/src/lib/components/sign-in-flow/sign-in-flow.component.ts +32 -0
  27. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.html +15 -0
  28. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.spec.ts +51 -0
  29. package/projects/angular-sdk/src/lib/components/sign-up-flow/sign-up-flow.component.ts +32 -0
  30. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.html +15 -0
  31. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.spec.ts +53 -0
  32. package/projects/angular-sdk/src/lib/components/sign-up-or-in-flow/sign-up-or-in-flow.component.ts +32 -0
  33. package/projects/angular-sdk/src/lib/descope-auth.module.ts +46 -0
  34. package/projects/angular-sdk/src/lib/services/descope-auth.guard.spec.ts +76 -0
  35. package/projects/angular-sdk/src/lib/services/descope-auth.guard.ts +16 -0
  36. package/projects/angular-sdk/src/lib/services/descope-auth.service.spec.ts +264 -0
  37. package/projects/angular-sdk/src/lib/services/descope-auth.service.ts +176 -0
  38. package/projects/angular-sdk/src/lib/services/descope.interceptor.spec.ts +102 -0
  39. package/projects/angular-sdk/src/lib/services/descope.interceptor.ts +76 -0
  40. package/projects/angular-sdk/src/lib/types/types.ts +10 -0
  41. package/projects/angular-sdk/src/lib/utils/constants.ts +8 -0
  42. package/projects/angular-sdk/src/lib/utils/helpers.spec.ts +103 -0
  43. package/projects/angular-sdk/src/lib/utils/helpers.ts +36 -0
  44. package/projects/angular-sdk/src/public-api.ts +13 -0
  45. package/projects/angular-sdk/tsconfig.lib.json +12 -0
  46. package/projects/angular-sdk/tsconfig.lib.prod.json +10 -0
  47. package/projects/angular-sdk/tsconfig.spec.json +11 -0
  48. package/projects/demo-app/.eslintrc.json +31 -0
  49. package/projects/demo-app/src/app/app-routing.module.ts +23 -0
  50. package/projects/demo-app/src/app/app.component.html +3 -0
  51. package/projects/demo-app/src/app/app.component.scss +16 -0
  52. package/projects/demo-app/src/app/app.component.spec.ts +37 -0
  53. package/projects/demo-app/src/app/app.component.ts +8 -0
  54. package/projects/demo-app/src/app/app.module.ts +52 -0
  55. package/projects/demo-app/src/app/home/home.component.html +23 -0
  56. package/projects/demo-app/src/app/home/home.component.scss +15 -0
  57. package/projects/demo-app/src/app/home/home.component.spec.ts +44 -0
  58. package/projects/demo-app/src/app/home/home.component.ts +61 -0
  59. package/projects/demo-app/src/app/interceptor/auth.interceptor.ts +20 -0
  60. package/projects/demo-app/src/app/login/login.component.html +12 -0
  61. package/projects/demo-app/src/app/login/login.component.spec.ts +42 -0
  62. package/projects/demo-app/src/app/login/login.component.ts +35 -0
  63. package/projects/demo-app/src/app/protected/protected.component.html +18 -0
  64. package/projects/demo-app/src/app/protected/protected.component.scss +8 -0
  65. package/projects/demo-app/src/app/protected/protected.component.spec.ts +42 -0
  66. package/projects/demo-app/src/app/protected/protected.component.ts +40 -0
  67. package/projects/demo-app/src/assets/.gitkeep +0 -0
  68. package/projects/demo-app/src/environments/conifg.ts +13 -0
  69. package/projects/demo-app/src/environments/environment.ts +19 -0
  70. package/projects/demo-app/src/favicon.ico +0 -0
  71. package/projects/demo-app/src/index.html +17 -0
  72. package/projects/demo-app/src/main.ts +7 -0
  73. package/projects/demo-app/src/styles.scss +21 -0
  74. package/projects/demo-app/tsconfig.app.json +10 -0
  75. package/projects/demo-app/tsconfig.spec.json +10 -0
  76. package/renovate.json +4 -0
  77. package/scripts/gitleaks/.gitleaks.toml +653 -0
  78. package/scripts/gitleaks/gitleaks.sh +34 -0
  79. package/scripts/setversion/setversion.js +20 -0
  80. package/setup-jest.ts +1 -0
  81. package/thirdPartyLicenseCollector_linux_amd64 +0 -0
  82. package/tsconfig.json +35 -0
@@ -0,0 +1,61 @@
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
+ }
@@ -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,12 @@
1
+ <descope
2
+ (success)="onSuccess()"
3
+ (error)="onError()"
4
+ [theme]="theme"
5
+ [flowId]="flowId"
6
+ [locale]="locale"
7
+ [redirectUrl]="redirectUrl"
8
+ [telemetryKey]="telemetryKey"
9
+ [tenant]="tenantId"
10
+ [debug]="debugMode"
11
+ [errorTransformer]="errorTransformer"
12
+ ></descope>
@@ -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
+ });
@@ -0,0 +1,35 @@
1
+ import { Component } from '@angular/core';
2
+ import { environment } from '../../environments/environment';
3
+ import { Router } from '@angular/router';
4
+
5
+ @Component({
6
+ selector: 'app-login',
7
+ templateUrl: './login.component.html'
8
+ })
9
+ export class LoginComponent {
10
+ flowId = environment.descopeFlowId ?? 'sign-up-or-in';
11
+ theme = (environment.descopeTheme as 'light' | 'dark' | 'os') ?? 'os';
12
+ telemetryKey = environment.descopeTelemetryKey ?? '';
13
+ debugMode = environment.descopeDebugMode ?? false;
14
+ tenantId = environment.descopeTenantId ?? '';
15
+ locale = environment.descopeLocale ?? '';
16
+ redirectUrl = environment.descopeRedirectUrl ?? '';
17
+
18
+ constructor(private router: Router) {}
19
+
20
+ errorTransformer = (error: { text: string; type: string }): string => {
21
+ const translationMap: { [key: string]: string } = {
22
+ SAMLStartFailed: 'Failed to start SAML flow'
23
+ };
24
+ return translationMap[error.type] || error.text;
25
+ };
26
+
27
+ onSuccess() {
28
+ console.log('SUCCESSFULLY LOGGED IN FROM WEB COMPONENT');
29
+ this.router.navigate(['/']).catch((err) => console.error(err));
30
+ }
31
+
32
+ onError() {
33
+ console.log('ERROR FROM LOG IN FLOW FROM WEB COMPONENT');
34
+ }
35
+ }
@@ -0,0 +1,18 @@
1
+ <descope
2
+ *ngIf="!stepUpSuccess"
3
+ (success)="onSuccess()"
4
+ (error)="onError()"
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
+
15
+ <ng-container *ngIf="stepUpSuccess">
16
+ <h2>STEP UP SUCCESS</h2>
17
+ <button (click)="goBack()">GO BACK</button>
18
+ </ng-container>
@@ -0,0 +1,8 @@
1
+ :host {
2
+ height: 100%;
3
+ display: flex;
4
+ justify-content: center;
5
+ align-items: center;
6
+ flex-direction: column;
7
+ gap: 20px;
8
+ }
@@ -0,0 +1,42 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ProtectedComponent } from './protected.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
+ import { NO_ERRORS_SCHEMA } from '@angular/core';
8
+
9
+ jest.mock('@descope/web-js-sdk');
10
+
11
+ describe('ProtectedComponent', () => {
12
+ let component: ProtectedComponent;
13
+ let fixture: ComponentFixture<ProtectedComponent>;
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
+ declarations: [ProtectedComponent],
28
+ schemas: [NO_ERRORS_SCHEMA],
29
+ providers: [
30
+ DescopeAuthConfig,
31
+ { provide: DescopeAuthConfig, useValue: { projectId: 'test' } }
32
+ ]
33
+ });
34
+ fixture = TestBed.createComponent(ProtectedComponent);
35
+ component = fixture.componentInstance;
36
+ fixture.detectChanges();
37
+ });
38
+
39
+ it('should create', () => {
40
+ expect(component).toBeTruthy();
41
+ });
42
+ });
@@ -0,0 +1,40 @@
1
+ import { Component } from '@angular/core';
2
+ import { Router } from '@angular/router';
3
+ import { environment } from '../../environments/environment';
4
+
5
+ @Component({
6
+ selector: 'app-protected',
7
+ templateUrl: './protected.component.html',
8
+ styleUrls: ['./protected.component.scss']
9
+ })
10
+ export class ProtectedComponent {
11
+ flowId = environment.descopeStepUpFlowId ?? 'sign-up-or-in';
12
+ theme = (environment.descopeTheme as 'light' | 'dark' | 'os') ?? 'os';
13
+ telemetryKey = environment.descopeTelemetryKey ?? '';
14
+ debugMode = environment.descopeDebugMode ?? false;
15
+ tenantId = environment.descopeTenantId ?? '';
16
+ locale = environment.descopeLocale ?? '';
17
+ redirectUrl = environment.descopeRedirectUrl ?? '';
18
+
19
+ stepUpSuccess = false;
20
+ constructor(private router: Router) {}
21
+
22
+ errorTransformer = (error: { text: string; type: string }): string => {
23
+ const translationMap: { [key: string]: string } = {
24
+ SAMLStartFailed: 'Failed to start SAML flow'
25
+ };
26
+ return translationMap[error.type] || error.text;
27
+ };
28
+
29
+ onSuccess() {
30
+ this.stepUpSuccess = true;
31
+ }
32
+
33
+ onError() {
34
+ console.log('ERROR FROM LOG IN FLOW FROM WEB COMPONENT');
35
+ }
36
+
37
+ goBack() {
38
+ this.router.navigate(['/']).catch((err) => console.error(err));
39
+ }
40
+ }
File without changes
@@ -0,0 +1,13 @@
1
+ export interface Env {
2
+ descopeProjectId: string;
3
+ descopeBaseUrl?: string;
4
+ descopeFlowId?: string;
5
+ descopeDebugMode?: false;
6
+ descopeTheme?: string;
7
+ descopeLocale?: string;
8
+ descopeRedirectUrl?: string;
9
+ descopeTenantId?: string;
10
+ descopeTelemetryKey?: string;
11
+ descopeStepUpFlowId?: string;
12
+ backendUrl?: string;
13
+ }
@@ -0,0 +1,19 @@
1
+ import { Env } from './conifg';
2
+
3
+ /**
4
+ * Create environment.development.ts file and copy content of this file to it.
5
+ * Fill the env vars according to your needs
6
+ */
7
+ export const environment: Env = {
8
+ descopeProjectId: '',
9
+ descopeBaseUrl: '',
10
+ descopeFlowId: '',
11
+ descopeDebugMode: false,
12
+ descopeTheme: '',
13
+ descopeLocale: '',
14
+ descopeRedirectUrl: '',
15
+ descopeTenantId: '',
16
+ descopeTelemetryKey: '',
17
+ descopeStepUpFlowId: '',
18
+ backendUrl: ''
19
+ };
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>DemoApp</title>
6
+ <base href="/" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
9
+ <link
10
+ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
11
+ rel="stylesheet"
12
+ />
13
+ </head>
14
+ <body>
15
+ <app-root></app-root>
16
+ </body>
17
+ </html>
@@ -0,0 +1,7 @@
1
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2
+
3
+ import { AppModule } from './app/app.module';
4
+
5
+ platformBrowserDynamic()
6
+ .bootstrapModule(AppModule)
7
+ .catch((err) => console.error(err));
@@ -0,0 +1,21 @@
1
+ /* You can add global styles to this file, and also import other style files */
2
+
3
+ body {
4
+ height: 100vh;
5
+ width: 100vw;
6
+ margin: 0;
7
+ font-family: 'Roboto', sans-serif;
8
+ }
9
+
10
+ button {
11
+ width: 200px;
12
+ height: 40px;
13
+ border: none;
14
+ background-color: #00ace1;
15
+ color: white;
16
+ cursor: pointer;
17
+
18
+ &:hover {
19
+ background-color: #047293;
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/app",
6
+ "types": []
7
+ },
8
+ "files": ["src/main.ts"],
9
+ "include": ["src/**/*.d.ts"]
10
+ }
@@ -0,0 +1,10 @@
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
+ "module": "CommonJs"
8
+ },
9
+ "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
10
+ }
package/renovate.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": ["config:base"]
4
+ }