Skip to content
Snippets Groups Projects
Commit a1540591 authored by Florent Poittevin's avatar Florent Poittevin
Browse files

Add api service to make a backend call

parent 6196a151
No related branches found
No related tags found
1 merge request!3Develop
...@@ -10,7 +10,11 @@ This project was generated with [Angular CLI](https://github.com/angular/angular ...@@ -10,7 +10,11 @@ This project was generated with [Angular CLI](https://github.com/angular/angular
### Apache ### Apache
Same as DLCM-Frontend in Php to mock Shibboleth Same as DLCM-Frontend Php app that use apache to mock Shibboleth, refer to the Apache part of the `README.md` of DLCM-Frontend app.
## Setting
Update proxy.conf.json to set the corresponding backend api.
## Install ## Install
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build", "build": "ng build",
"test": "ng test", "test": "ng test",
"lint": "ng lint", "lint": "ng lint",
......
{
"/admin": {
"target": "http://localhost:16115/dlcm",
"secure": false,
"logLevel": "info",
"pathRewrite": {
},
"changeOrigin": false
},
"/ingest": {
"target": "http://localhost:16116/dlcm",
"secure": false,
"logLevel": "info",
"pathRewrite": {
},
"changeOrigin": false
},
"/preingest": {
"target": "http://localhost:16116/dlcm",
"secure": false,
"logLevel": "info",
"pathRewrite": {
},
"changeOrigin": false
},
"/access": {
"target": "http://localhost:16118/dlcm",
"secure": false,
"logLevel": "info",
"pathRewrite": {
},
"changeOrigin": false
}
}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
Welcome to {{ title }}! Welcome to {{ title }}!
</h1> </h1>
<button (click)="test()">Get Organizations Units</button>
<dlcm-home></dlcm-home> <dlcm-home></dlcm-home>
<router-outlet></router-outlet> <router-outlet></router-outlet>
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {OAuthService} from 'angular-oauth2-oidc'; import {OAuthService} from 'angular-oauth2-oidc';
import {AppService} from './app.service';
@Component({ @Component({
selector: 'dlcm-root', selector: 'dlcm-root',
...@@ -10,7 +11,7 @@ import {OAuthService} from 'angular-oauth2-oidc'; ...@@ -10,7 +11,7 @@ import {OAuthService} from 'angular-oauth2-oidc';
export class AppComponent { export class AppComponent {
title = 'DLCM-Frontend'; title = 'DLCM-Frontend';
constructor(private oauthService: OAuthService) { constructor(private oauthService: OAuthService, private appService: AppService) {
this.checkTokenInUrl(); this.checkTokenInUrl();
} }
...@@ -24,5 +25,10 @@ export class AppComponent { ...@@ -24,5 +25,10 @@ export class AppComponent {
disableOAuth2StateCheck: true, disableOAuth2StateCheck: true,
}; };
this.oauthService.tryLogin(option); this.oauthService.tryLogin(option);
}
test() {
this.appService.getOrganizationUnits();
} }
} }
...@@ -10,6 +10,7 @@ import {AppComponent} from './app.component'; ...@@ -10,6 +10,7 @@ import {AppComponent} from './app.component';
import {HomeComponent} from './home/home.component'; import {HomeComponent} from './home/home.component';
import {DlcmInterceptor} from './dlcm.interceptor'; import {DlcmInterceptor} from './dlcm.interceptor';
import {authConfig, authModuleConfig} from './auth.config'; import {authConfig, authModuleConfig} from './auth.config';
import {AppService} from './app.service';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -26,6 +27,7 @@ import {authConfig, authModuleConfig} from './auth.config'; ...@@ -26,6 +27,7 @@ import {authConfig, authModuleConfig} from './auth.config';
OAuthModule.forRoot(authModuleConfig), OAuthModule.forRoot(authModuleConfig),
], ],
providers: [ providers: [
AppService,
{provide: OAuthModuleConfig, useValue: authModuleConfig}, {provide: OAuthModuleConfig, useValue: authModuleConfig},
{provide: ValidationHandler, useClass: JwksValidationHandler}, {provide: ValidationHandler, useClass: JwksValidationHandler},
// {provide: OAuthStorage, useClass: DlcmStorage}, // {provide: OAuthStorage, useClass: DlcmStorage},
......
...@@ -10,7 +10,7 @@ export class AppService { ...@@ -10,7 +10,7 @@ export class AppService {
} }
getOrganizationUnits() { getOrganizationUnits() {
this.http.get('http://localhost:16118/dlcm/access/oai-sets/organizational-units') this.http.post('/access/oai-sets/organizational-units', ['707c7bc3-bfa1-4846-a62f-5ce95ecf1444'])
.subscribe((data) => { .subscribe((data) => {
console.log('test : ', data); console.log('test : ', data);
}); });
......
...@@ -19,7 +19,7 @@ export const authConfig: AuthConfig = { ...@@ -19,7 +19,7 @@ export const authConfig: AuthConfig = {
export const authModuleConfig: OAuthModuleConfig = { export const authModuleConfig: OAuthModuleConfig = {
// Inject "Authorization: Bearer ..." header for these APIs: // Inject "Authorization: Bearer ..." header for these APIs:
resourceServer: { resourceServer: {
allowedUrls: ['http://localhost'], allowedUrls: ['/'],
sendAccessToken: true, sendAccessToken: true,
}, },
}; };
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {OAuthService} from 'angular-oauth2-oidc';
@Injectable() @Injectable()
export class DlcmInterceptor implements HttpInterceptor { export class DlcmInterceptor implements HttpInterceptor {
constructor() { constructor(private oauthService: OAuthService) {
} }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone();
request = request.clone({});
return next.handle(request); return next.handle(request);
} }
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false production: false,
}; };
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment