[ADF-2289] Login with oauth2 provider (#2924)

* Fix oauth2 provider

* Add the schema validation

* Improve the login doc with provider "OAUTH"

* fix doc
This commit is contained in:
Maurizio Vitale 2018-02-12 15:25:03 +00:00 committed by Eugenio Romano
parent 3368607aff
commit 37561d1d27
4 changed files with 64 additions and 2 deletions

View File

@ -41,7 +41,7 @@ Authenticates to Alfresco Content Services and Alfresco Process Services.
| logoImageUrl | `string` | `'./assets/images/alfresco-logo.svg'` | Path to a custom logo image. | | logoImageUrl | `string` | `'./assets/images/alfresco-logo.svg'` | Path to a custom logo image. |
| backgroundImageUrl | `string` | `'./assets/images/background.svg'` | Path to a custom background image. | | backgroundImageUrl | `string` | `'./assets/images/background.svg'` | Path to a custom background image. |
| copyrightText | `string` | `'\u00A9 2016 Alfresco Software, Inc. All Rights Reserved.'` | The copyright text below the login box. | | copyrightText | `string` | `'\u00A9 2016 Alfresco Software, Inc. All Rights Reserved.'` | The copyright text below the login box. |
| providers | `string` | | Possible valid values are ECM, BPM or ALL. By default, this component will log in only to ECM. If you want to log in in both systems then use ALL. | | providers | `string` | | Possible valid values are ECM, BPM or ALL. By default, this component will log in only to ECM. If you want to log in in both systems then use ALL. There is also a way to call your Auth token API using the string "OAUTH" (supported only for BPM) |
| fieldsValidation | `any` | | Custom validation rules for the login form. | | fieldsValidation | `any` | | Custom validation rules for the login form. |
| disableCsrf | `boolean` | | Prevents the CSRF Token from being submitted. Only valid for Alfresco Process Services. | | disableCsrf | `boolean` | | Prevents the CSRF Token from being submitted. Only valid for Alfresco Process Services. |
| successRoute | `string` | `null` | Route to redirect to on successful login. | | successRoute | `string` | `null` | Route to redirect to on successful login. |
@ -186,6 +186,46 @@ export class MyCustomLogin {
} }
``` ```
### Call an external identity provider to fetch the auth token
If needed it is possible to call an external provider to identify the user.
**app.config.json**
```json
{
"oauth2" : {
"host": "http://myhost.com",
"authPath": "/my-custom-auth/token",
"clientId": "my-client-id",
"secret": ""
}
}
```
**MyCustomLogin.component.html**
```html
<adf-login
[providers]="'OAUTH'"
(success)="onMyAuthLogin($event)">
</adf-login>
```
**MyCustomLogin.component.ts**
```ts
export class MyCustomLogin {
constructor(public router: Router) {
}
onMyAuthLogin($event) {
console.log("My token " + $event.token.ticket)
this.router.navigate(['/home']);
}
}
```
### Controlling form submit execution behaviour ### Controlling form submit execution behaviour
If absolutely needed it is possible taking full control over form If absolutely needed it is possible taking full control over form

View File

@ -332,6 +332,17 @@
} }
} }
} }
},
"oauth2": {
"description": "AUTH configuration parameters",
"type": "object",
"required": [ "host", "clientId", "secret" ],
"properties": {
"host": { "type": "string" },
"authPath": { "type": "string" },
"clientId": { "type": "string" },
"secret": { "type": "string" }
}
} }
} }
} }

View File

@ -88,7 +88,8 @@ export class AlfrescoApiService {
hostEcm: this.appConfig.get<string>('ecmHost'), hostEcm: this.appConfig.get<string>('ecmHost'),
hostBpm: this.appConfig.get<string>('bpmHost'), hostBpm: this.appConfig.get<string>('bpmHost'),
contextRoot: 'alfresco', contextRoot: 'alfresco',
disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true' disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true',
oauth2 : this.appConfig.get<any>('oauth2')
}); });
} }
} }

View File

@ -174,6 +174,7 @@ export class AuthenticationService {
saveTickets(): void { saveTickets(): void {
this.saveTicketEcm(); this.saveTicketEcm();
this.saveTicketBpm(); this.saveTicketBpm();
this.saveTicketAuth();
} }
/** /**
@ -194,6 +195,15 @@ export class AuthenticationService {
} }
} }
/**
* The method save the AUTH ticket in the Storage
*/
saveTicketAuth(): void {
if (this.alfrescoApi.getInstance() && (<any>this.alfrescoApi.getInstance()).getTicketAuth()) {
this.storage.setItem('ticket-AUTH', (<any>this.alfrescoApi.getInstance()).getTicketAuth());
}
}
/** /**
* The method return true if user is logged in on ecm provider * The method return true if user is logged in on ecm provider
* *