Skip to content

Commit

Permalink
Feature/component qa fix (#16)
Browse files Browse the repository at this point in the history
* fix signup type in prebuilt component
* use github SPA src

### DETAILS

* update libs

* fix signup button action

* use signin for navbar

* update SPA to local latest build

* update SPA to debug Cookies attributes

* update SPA for cookies debugging

* update SPA for cookies with proper expiration

* update SPA with clean ccode

* use SPA v0.1.5

* debug auth client config

* debug client creation

* debug cryptrSpa

* debug cryptrSpa differeently

* linting

* rollback to git branch

* use release v0.1.5 branch from git

* use spa from npm

* rollback to release branch with yarn process

* try npmjs with create client

* use github src

* revert client to direct call

* update types

* cleanup console log for invalid grant

* use npmjs src

* test client in app module playground

* fix import

* clean up app module

* use latest git v0.1.5

* use double quote

* linting
  • Loading branch information
tuxtux59 authored Feb 19, 2021
1 parent 856b3ac commit 6a82a8d
Show file tree
Hide file tree
Showing 9 changed files with 811 additions and 441 deletions.
462 changes: 231 additions & 231 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@angular/platform-browser": "^10.2.4",
"@angular/platform-browser-dynamic": "^10.2.4",
"@angular/router": "^10.2.4",
"@cryptr/cryptr-spa-js": "git://github.com/cryptr-auth/cryptr-spa-js.git#enhancement/rotation-tokens",
"@cryptr/cryptr-spa-js": "github:cryptr-auth/cryptr-spa-js#release/v0.1.5",
"dotenv": "^8.2.0",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
Expand Down
746 changes: 547 additions & 199 deletions projects/cryptr/cryptr-angular/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion projects/cryptr/cryptr-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"make-badges": "istanbul-badges-readme"
},
"dependencies": {
"@cryptr/cryptr-spa-js": "git://github.com/cryptr-auth/cryptr-spa-js.git#enhancement/rotation-tokens",
"@cryptr/cryptr-spa-js": "github:cryptr-auth/cryptr-spa-js#release/v0.1.5",
"tslib": "^2.0.0"
},
"author": "Cryptr <thibaud@cryptr.co> (https://www.cryptr.co)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class AccountAccessButtonComponent implements OnChanges {
}

signUpWithRedirect(): void {
this.auth.signInWithRedirect(DEFAULT_SCOPE, this.locale, this.redirectUri);
this.auth.signUpWithRedirect(DEFAULT_SCOPE, this.locale, this.redirectUri);
}

currentToggleBtnClass(): string {
Expand Down
11 changes: 11 additions & 0 deletions projects/cryptr/cryptr-angular/src/lib/auth.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import { AuthClientConfig } from './auth.config';
export class CryptrClientFactory {
static createClient(configFactory: AuthClientConfig): any {
const config = configFactory.get();

try {
console.log(CryptrSpa);
} catch (error) {
console.error('cryptr spa seems not to be loaded');
console.error(error);
}
try {
if (!config) {
throw new Error(
'Configuration must be specified either through AuthModule.forRoot or through AuthClientConfig.set'
);
} else {
console.log(config);
const { default_redirect_uri, httpInterceptor: { apiRequestsToSecure } } = config;
if (apiRequestsToSecure === undefined || apiRequestsToSecure.length === 0) {
throw new Error(
Expand All @@ -19,7 +27,10 @@ export class CryptrClientFactory {
}
console.warn(`The path ${default_redirect_uri} have to be decorated with 'canActivate: [AuthGuard]' options`);
}
console.log('before client creation');
const client = new CryptrSpa.client(config);
console.log(client);
console.log('after client creation');
return client;
} catch (error) {
console.error('authclient error');
Expand Down
18 changes: 16 additions & 2 deletions projects/cryptr/cryptr-angular/src/lib/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ export interface AuthResponseError {
field: string;
message: string;
}
export interface TokenError {
http_response: any;
error: string;
error_description: string;
}

export interface RefreshStore {
refresh_token: string;
access_token_expiration_date: Date;
access_token_expiration_date: number;
refresh_expiration_date: number;
refresh_leeway: number;
refresh_retry: number;
}

export interface CryptrClient {
Expand All @@ -47,12 +56,17 @@ export interface CryptrClient {
signUpWithRedirect(scope?: string, redirectUri?: string, locale?: string): Promise<void>;
inviteWithRedirect(scope?: string, redirectUri?: string, locale?: string): Promise<void>;
handleInvitationState(scope?: string): Promise<void>;
handleTokensErrors(errors: TokenError[]): boolean;
handleNewTokens(refreshStore: RefreshStore, tokens?: any): void;
handleRedirectCallback(): Promise<any>;
canRefresh(refreshStore: RefreshStore): boolean;
getRefreshStore(): RefreshStore;
handleRefreshTokens(): Promise<boolean>;
recurringRefreshToken(refreshTokenWrapper: RefreshStore): void;
getUser(): object | undefined;
getClaimsFromAccess(accessToken: string): object | null;
canHandleAuthentication(searchParams?: string): boolean;
canHandleInvitation(searchParams?: string): Promise<boolean>;
canHandleInvitation(searchParams?: string): boolean;
userAccountAccess(): Promise<import('axios').AxiosResponse<any> | undefined>;
logOut(callback: any, location?: Location): Promise<boolean>;
decoratedRequest(axiosRequestConfig: any): any;
Expand Down
6 changes: 2 additions & 4 deletions projects/playground/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserModule } from '@angular/platform-browser';
import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -11,13 +11,11 @@ import { GraphqlComponent } from './pages/graphql/graphql.component';
import { GrowthHackerComponent } from './pages/growth-hacker/growth-hacker.component';
import { MyCoursesComponent } from './pages/my-courses/my-courses.component';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
// import { CommonModule } from '@angular/common'
// import * as Sentry from '@sentry/angular';
import { Router } from '@angular/router';
import { environment } from '../environments/environment';
import { AuthModule } from 'projects/cryptr/cryptr-angular/src/lib/auth.module';
import { AccountAccessButtonComponent } from 'projects/cryptr/cryptr-angular/src/lib/account-access-button/account-access-button.component';
import { AuthHttpInterceptor } from 'projects/cryptr/cryptr-angular/src/lib/auth.interceptor';

@NgModule({
declarations: [
AppComponent,
Expand Down
3 changes: 1 addition & 2 deletions projects/playground/src/app/components/nav/nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class NavComponent implements OnInit {
// O: normal, 1: invalid_grant, 2: expired
logOutPopupStyle = 0;
locale = 'fr';
signType = "signup"
signType = 'signin';
redirectUri = 'http://localhost:4200/';

constructor(public auth: AuthService, private router: Router) {
Expand All @@ -38,7 +38,6 @@ export class NavComponent implements OnInit {
// CRYPTR BLOCK
cryptrListeners(): void {
window.addEventListener(CryptrSpa.events.REFRESH_INVALID_GRANT, (e) => {
console.error(e);
this.logOut(1);
});
window.addEventListener(CryptrSpa.events.REFRESH_EXPIRED, (e) => {
Expand Down

0 comments on commit 6a82a8d

Please sign in to comment.