Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gsa with api sandbox #233

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/golden-sample-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"development": {
"browserTarget": "golden-sample-app:build:development"
"browserTarget": "golden-sample-app:build:development",
"proxyConfig": "./apps/golden-sample-app/proxy.conf.json"
},
"production": {
"browserTarget": "golden-sample-app:build:production"
Expand Down
9 changes: 9 additions & 0 deletions apps/golden-sample-app/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"context": "/api",
"target": "https://app.dev.sdbxaz.azure.backbaseservices.com/",
"secure": false,
"changeOrigin": true,
"headers": {
"X-SDBXAZ-API-KEY": "<place-your-api-key-here>"
}
}
45 changes: 27 additions & 18 deletions apps/golden-sample-app/src/app/auth/interceptor/auth.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {
HttpEvent,
HttpHandler,
HttpHeaders,
HttpInterceptor,
HttpRequest,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { OAuthService } from 'angular-oauth2-oidc';
import { OAuthService, TokenResponse } from 'angular-oauth2-oidc';
import { Observable, ReplaySubject, from, throwError } from 'rxjs';
import {
catchError,
exhaustMap,
from,
map,
Observable,
ReplaySubject,
share,
switchMap,
take,
throwError,
} from 'rxjs';
} from 'rxjs/operators';

import { Injectable } from '@angular/core';
import { environment } from './../../../environments/environment.prod';
import { isInvalidToken401 } from '../utils/auth.utils';

/**
Expand Down Expand Up @@ -52,25 +52,34 @@ export class AuthInterceptor implements HttpInterceptor {
catchError((error) => {
if (isInvalidToken401(error)) {
this.triggerRefresh$$.next();

return this.refreshToken$.pipe(
take(1),
catchError(() => throwError(() => error)),
switchMap((token) =>
next.handle(
request.clone({
headers: request.headers.set(
'Authorization',
'Bearer ' + token
),
})
)
)
switchMap((token) => this.handleTokenRefresh(request, next, token))
);
}
return throwError(() => error);
})
);
}

private readonly refreshToken = () => from(this.oAuthService.refreshToken());
private handleTokenRefresh(
request: HttpRequest<unknown>,
next: HttpHandler,
token: string
): Observable<HttpEvent<unknown>> {
return next.handle(
request.clone({
headers: new HttpHeaders({
Authorization: `Bearer ${token}`,
'X-SDBXAZ-API-KEY': environment.sandboxApiKey,
}),
})
);
}

private refreshToken(): Observable<TokenResponse> {
return from(this.oAuthService.refreshToken());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const environment: Environment = {
bbApiKey: 'a554d1b4-6514-4f33-8211-3f52a03ca142',
telemetryCollectorURL: 'https://rum-collector.backbase.io/v1/traces',
env: 'mock',
sandboxApiKey: 'mock-api-key',
};

export const authConfig: AuthConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const environment: Environment = {
bbApiKey: 'a554d1b4-6514-4f33-8211-3f52a03ca142',
telemetryCollectorURL: 'https://rum-collector.backbase.io/v1/traces',
env: 'production',
sandboxApiKey: '<place-your-api-key-here>',
};

export const authConfig: AuthConfig = {
Expand Down
11 changes: 6 additions & 5 deletions apps/golden-sample-app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { Provider } from '@angular/core';
import { AuthConfig } from 'angular-oauth2-oidc';
import { AchPositivePayInterceptor } from '../app/interceptors/ach-positive-pay.interceptor';
import { AuthConfig } from 'angular-oauth2-oidc';
import { Environment } from './type';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { Provider } from '@angular/core';

const mockProviders: Provider[] = [
{
Expand All @@ -18,7 +18,7 @@ const mockProviders: Provider[] = [

export const environment: Environment = {
production: false,
apiRoot: 'https://app.prd.sdbxaz.azure.backbaseservices.com/api',
apiRoot: '/api',
mockProviders,
locales: ['en-US', 'nl-NL'],
common: {
Expand All @@ -28,12 +28,13 @@ export const environment: Environment = {
bbApiKey: 'a554d1b4-6514-4f33-8211-3f52a03ca142',
telemetryCollectorURL: 'https://rum-collector.backbase.io/v1/traces',
env: 'local',
sandboxApiKey: '<place-your-api-key-here>',
};

export const authConfig: AuthConfig = {
// Url of the Identity Provider
issuer:
'https://identity.prd.sdbxaz.azure.backbaseservices.com/auth/realms/customer',
'https://identity.dev.sdbxaz.azure.backbaseservices.com/auth/realms/customer',

// URL of the SPA to redirect the user to after login
redirectUri: document.baseURI,
Expand Down
1 change: 1 addition & 0 deletions apps/golden-sample-app/src/environments/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface Environment {
bbApiKey?: string;
telemetryCollectorURL?: string;
env?: string;
sandboxApiKey: string;
}
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: '3'

services:
web:
Expand All @@ -12,8 +12,8 @@ services:
HOSTNAME: localhost
PORT: 4200
BASE_HREF: /
API_ROOT: https://app.prd.sdbxaz.azure.backbaseservices.com/api
AUTH_URL: https://identity.prd.sdbxaz.azure.backbaseservices.com/auth/realms/customer
API_ROOT: https://app.dev.sdbxaz.azure.backbaseservices.com/api
AUTH_URL: https://identity.dev.sdbxaz.azure.backbaseservices.com/auth/realms/customer
AUTH_SCOPE: openid profile email
AUTH_CLIENT_ID: bb-web-client
LOCALES: en,nl
Expand Down
Loading