| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 1 |
+## Autenticazione ADFS in applicazione Angular 2 |
|
| 2 |
+ |
|
| 3 |
+### src/app/App.Module.ts |
|
| 4 |
+<pre> |
|
| 5 |
+import { Http, HttpModule, Response, Headers, RequestOptions } from '@angular/http';
|
|
| 6 |
+import { AdfsComponent } from 'com-ff3d-adfs';
|
|
| 7 |
+ |
|
| 8 |
+declarations: [ |
|
| 9 |
+ ... |
|
| 10 |
+ AdfsComponent |
|
| 11 |
+] |
|
| 12 |
+imports: [ |
|
| 13 |
+ ... |
|
| 14 |
+ HttpModule |
|
| 15 |
+], |
|
| 16 |
+</pre> |
|
| 17 |
+ |
|
| 18 |
+### src/environments/environment.ts |
|
| 19 |
+<pre> |
|
| 20 |
+export const environment = {
|
|
| 21 |
+ ... |
|
| 22 |
+ portalUrl: 'http://localhost:4200', // Url del portale |
|
| 23 |
+ ADFSUrl: 'http://127.0.0.1/ff3dMVCAdfs/home/index/', // Url del MVC su cui fare autenticazione adfs |
|
| 24 |
+ logoutADFSUrl: 'https://mpf.manutencoop.it/adfs/ls/?wa=wsignout1.0' // Url per logout |
|
| 25 |
+}; |
|
| 26 |
+</pre> |
|
| 27 |
+ |
|
| 28 |
+### src/app/app.component.html |
|
| 29 |
+<pre><app-adfs></app-adfs></pre> |
|
| 30 |
+ |
|
| 31 |
+### tsconfig.json |
|
| 32 |
+<pre> |
|
| 33 |
+"include": [ |
|
| 34 |
+ "src/**/*" |
|
| 35 |
+], |
|
| 36 |
+"files": [ |
|
| 37 |
+ "node_modules/com-ff3d-adfs/index.ts" |
|
| 38 |
+] |
|
| 39 |
+</pre> |
| 0 | 40 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 1 |
+.error-page {
|
|
| 2 |
+ background-color: red; |
|
| 3 |
+ position: absolute; |
|
| 4 |
+ height:100%; |
|
| 5 |
+ width:100%; |
|
| 6 |
+ text-align: center; |
|
| 7 |
+ color:white; |
|
| 8 |
+ display: table; |
|
| 9 |
+ z-index: 99999; |
|
| 10 |
+} |
|
| 11 |
+ |
|
| 12 |
+.fa {
|
|
| 13 |
+ font-size: 50px; |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 16 |
+a {
|
|
| 17 |
+ text-decoration: underline; |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+.child {
|
|
| 21 |
+ display: table-cell; |
|
| 22 |
+ vertical-align: middle; |
|
| 23 |
+} |
|
| 0 | 24 |
\ No newline at end of file |
| 1 | 25 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,17 @@ |
| 1 |
+<div> |
|
| 2 |
+ <div *ngIf="errorPage" class="error-page"> |
|
| 3 |
+ <div class="col-md-12" class="child"> |
|
| 4 |
+ |
|
| 5 |
+ <div class="col-md-12"> |
|
| 6 |
+ <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
|
| 7 |
+ </div> |
|
| 8 |
+ <div class="col-md-12"> |
|
| 9 |
+ <h4>Errore: {{ errorMessage }}</h4>
|
|
| 10 |
+ </div> |
|
| 11 |
+ <div class="col-md-12"> |
|
| 12 |
+ <a href="{{ logoutUrl }}">LOGOUT APPLICAZIONE</a>
|
|
| 13 |
+ </div> |
|
| 14 |
+ |
|
| 15 |
+ </div> |
|
| 16 |
+ </div> |
|
| 17 |
+</div> |
| 0 | 18 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,38 @@ |
| 1 |
+import { Component } from '@angular/core';
|
|
| 2 |
+import { environment } from 'environments/environment';
|
|
| 3 |
+import { Http, HttpModule, Response, Headers, RequestOptions } from '@angular/http';
|
|
| 4 |
+ |
|
| 5 |
+@Component({
|
|
| 6 |
+ selector: 'app-adfs', |
|
| 7 |
+ templateUrl: './adfs.component.html', |
|
| 8 |
+ styleUrls: ['./adfs.component.css'] |
|
| 9 |
+}) |
|
| 10 |
+export class AdfsComponent {
|
|
| 11 |
+ errorPage = false; |
|
| 12 |
+ errorMessage = ''; |
|
| 13 |
+ logoutUrl: string = environment.logoutADFSUrl; |
|
| 14 |
+ |
|
| 15 |
+ constructor(private http: Http) {
|
|
| 16 |
+ const url = new URL(window.location.href); |
|
| 17 |
+ const callback = btoa(environment.portalUrl); |
|
| 18 |
+ |
|
| 19 |
+ if (url.searchParams.get('user') == null || url.searchParams.get('timespan') == null || url.searchParams.get('bearer') == null) {
|
|
| 20 |
+ // Vai ad autenticazione ADFS |
|
| 21 |
+ console.log('Vai ad autenticazione ADFS');
|
|
| 22 |
+ window.location.href = environment.ADFSUrl + callback; |
|
| 23 |
+ |
|
| 24 |
+ } else {
|
|
| 25 |
+ |
|
| 26 |
+ if (url.searchParams.get('error') == null) {
|
|
| 27 |
+ console.log('bearer ' + url.searchParams.get('bearer'));
|
|
| 28 |
+ localStorage.setItem('token', 'bearer ' + url.searchParams.get('bearer'));
|
|
| 29 |
+ } else {
|
|
| 30 |
+ localStorage.clear(); |
|
| 31 |
+ this.errorMessage = url.searchParams.get('error');
|
|
| 32 |
+ this.errorPage = true; |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ } |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+} |
| 0 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,18 @@ |
| 1 |
+{
|
|
| 2 |
+ "name": "com-ff3d-adfs", |
|
| 3 |
+ "version": "1.0.4", |
|
| 4 |
+ "description": "ff3d adfs module", |
|
| 5 |
+ "main": "index.ts", |
|
| 6 |
+ "scripts": {
|
|
| 7 |
+ "test": "echo \"Error: no test specified\" && exit 1" |
|
| 8 |
+ }, |
|
| 9 |
+ "repository": {
|
|
| 10 |
+ "type": "git", |
|
| 11 |
+ "url": "https://npm.ff3d.com" |
|
| 12 |
+ }, |
|
| 13 |
+ "keywords": [ |
|
| 14 |
+ "adfs" |
|
| 15 |
+ ], |
|
| 16 |
+ "author": "Giuseppe Di Maria", |
|
| 17 |
+ "license": "ISC" |
|
| 18 |
+} |