Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/id1945/angular12-wso2-is-sso
Single Sign-on (SSO) Auth0 Angular 2+
https://github.com/id1945/angular12-wso2-is-sso
angular login openid single-sign-on sso token
Last synced: 17 days ago
JSON representation
Single Sign-on (SSO) Auth0 Angular 2+
- Host: GitHub
- URL: https://github.com/id1945/angular12-wso2-is-sso
- Owner: id1945
- Created: 2021-09-07T14:27:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-07T14:54:40.000Z (over 3 years ago)
- Last Synced: 2024-11-19T21:34:41.699Z (3 months ago)
- Topics: angular, login, openid, single-sign-on, sso, token
- Language: TypeScript
- Homepage:
- Size: 1.76 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ví dụ về Single Sign-on (SSO) Auth0
## Cài đặt
Cài đặt thư viện [angular-oauth2-oidc](https://www.npmjs.com/package/angular-oauth2-oidc)
```bash
npm install angular-oauth2-oidc --save
```## Structure
```tree
├───app
│ └───home
├───assets
└───environments
```## AppModule
```typescript
import { OAuthModule } from 'angular-oauth2-oidc';@NgModule({
declarations: [
AppComponent,
HomeComponent
],
imports: [
...
OAuthModule.forRoot() // Import SSO
],
providers: [], // Providers SSO
bootstrap: [AppComponent]
})
export class AppModule { }
```## Environment
```json
export const environment = {
production: false,
sso: {
"clientId": "nPzsAOuuadNBF4sZUC4YAre43nca",
"issuer": "https://sso.tcmotor.vn/oauth2/token",
"redirectUri": "http://localhost:4200/callback",
"loginUrl": "https://sso.tcmotor.vn/oauth2/authorize",
"tokenEndpoint": "https://sso.tcmotor.vn/oauth2/token",
"userinfoEndpoint": "https://sso.tcmotor.vn/oauth2/userinfo",
"requireHttps": false,
"requestAccessToken": true,
"disableAtHashCheck": false,
"showDebugInformation": true,
"scope": "openid",
"responseType": "id_token token"
}
};
```## AppConponent
```typescript
export class AppComponent {constructor(public sso: OAuthService) {
this.configSSO();
}/**
* Configuring Single Sign-On
*/
private configSSO(): void {
this.sso.configure(ssoConfig);/** enable below validation only if jwks object is defined as part of oauthconfig obj */
// this.sso.tokenValidationHandler = new JwksValidationHandler();
this.sso.setStorage(sessionStorage);/** commented below because below resource is protected by some identity server ex: wso2 */
// this.sso.loadDiscoveryDocumentAndTryLogin();this.sso.tryLogin();
}
}
```
## HomeComponent```typescript
export class HomeComponent implements OnInit {constructor(public sso: OAuthService) { }
/**
* Init component
*/
ngOnInit(): void {
// sessionStorage
console.log('sessionStorageExpiresAt: ', sessionStorage.getItem('expires_at'));
console.log('sessionStorageAccessToken: ', sessionStorage.getItem('access_token'));
// Form service
console.log('getAccessToken: ', this.sso.getAccessToken())
console.log('hasValidAccessToken: ', this.sso.hasValidAccessToken())
}}
```## HomeComponent - html
```xml
Author: DaiDH
Login
Logout
![]()
Expiration Time: {{sso.getAccessTokenExpiration() | date: 'dd-MM-yyyy HH:mm:ss'}}
AccessToken:
{{sso.getAccessToken() | json}}
```![Screenshot](https://raw.githubusercontent.com/id1945/angular12-wso2-is-sso/master/login.PNG)
![Screenshot](https://raw.githubusercontent.com/id1945/angular12-wso2-is-sso/master/logout.PNG)
## License
[MIT](https://choosealicense.com/licenses/mit/)