File tree Expand file tree Collapse file tree 9 files changed +57
-40
lines changed Expand file tree Collapse file tree 9 files changed +57
-40
lines changed Original file line number Diff line number Diff line change 3434 "angular-oauth2-oidc-jwks" : " ^9.0.0" ,
3535 "base64-js" : " ^1.3.0" ,
3636 "bootstrap" : " ^3.3.7" ,
37+ "js-sha256" : " ^0.9.0" ,
3738 "jsrsasign" : " ^8.0.12" ,
3839 "rxjs" : " 6.5.4" ,
3940 "rxjs-compat" : " ^6.5.2" ,
Original file line number Diff line number Diff line change 66 },
77 "version" : " 9.0.1" ,
88 "repository" : " manfredsteyer/angular-oauth2-oidc" ,
9+ "dependencies" : {
10+ "js-sha256" : " ^0.9.0"
11+ },
912 "peerDependencies" : {
1013 "@angular/common" : " >=8.0.0" ,
1114 "@angular/core" : " >=8.0.0"
Original file line number Diff line number Diff line change @@ -1436,8 +1436,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14361436 public tryLogin ( options : LoginOptions = null ) : Promise < boolean > {
14371437 if ( this . config . responseType === 'code' ) {
14381438 return this . tryLoginCodeFlow ( options ) . then ( _ => true ) ;
1439- }
1440- else {
1439+ } else {
14411440 return this . tryLoginImplicitFlow ( options ) ;
14421441 }
14431442 }
@@ -2243,6 +2242,12 @@ export class OAuthService extends AuthConfig implements OnDestroy {
22432242 if ( crypto ) {
22442243 let bytes = new Uint8Array ( size ) ;
22452244 crypto . getRandomValues ( bytes ) ;
2245+
2246+ // Needed for IE
2247+ if ( ! bytes . map ) {
2248+ ( bytes as any ) . map = Array . prototype . map ;
2249+ }
2250+
22462251 bytes = bytes . map ( x => unreserved . charCodeAt ( x % unreserved . length ) ) ;
22472252 id = String . fromCharCode . apply ( null , bytes ) ;
22482253 } else {
Original file line number Diff line number Diff line change 11import { Injectable } from '@angular/core' ;
22
3+ import { sha256 } from 'js-sha256' ;
4+
5+
36/**
47 * Abstraction for crypto algorithms
58*/
@@ -11,10 +14,23 @@ export abstract class HashHandler {
1114export class DefaultHashHandler implements HashHandler {
1215
1316 async calcHash ( valueToHash : string , algorithm : string ) : Promise < string > {
14- const encoder = new TextEncoder ( ) ;
15- const data = encoder . encode ( valueToHash ) ;
16- const hashArray = await window . crypto . subtle . digest ( algorithm , data ) ;
17- return this . toHashString ( hashArray ) ;
17+ // const encoder = new TextEncoder();
18+ // const hashArray = await window.crypto.subtle.digest(algorithm, data);
19+ // const data = encoder.encode(valueToHash);
20+
21+ const hashArray = sha256 . array ( valueToHash ) ;
22+ // const hashString = this.toHashString(hashArray);
23+ const hashString = this . toHashString2 ( hashArray ) ;
24+
25+ return hashString ;
26+ }
27+
28+ toHashString2 ( byteArray : number [ ] ) {
29+ let result = '' ;
30+ for ( let e of byteArray ) {
31+ result += String . fromCharCode ( e ) ;
32+ }
33+ return result ;
1834 }
1935
2036 toHashString ( buffer : ArrayBuffer ) {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export class AppComponent {
1515 constructor ( private oauthService : OAuthService ) {
1616 this . oauthService . configure ( authCodeFlowConfig ) ;
1717 this . oauthService . loadDiscoveryDocumentAndLogin ( ) ;
18+ this . oauthService . setupAutomaticSilentRefresh ( ) ;
1819
1920 // Automatically load user profile
2021 this . oauthService
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
22import { NgModule } from '@angular/core' ;
33
44import { AppComponent } from './app.component' ;
5- import { OAuthModule } from 'angular-oauth2-oidc' ;
5+ import { OAuthModule , OAuthStorage } from 'angular-oauth2-oidc' ;
66import { HttpClientModule } from '@angular/common/http' ;
77
88@NgModule ( {
@@ -14,7 +14,9 @@ import { HttpClientModule } from '@angular/common/http';
1414 declarations : [
1515 AppComponent
1616 ] ,
17- providers : [ ] ,
17+ providers : [
18+ { provide : OAuthStorage , useValue : localStorage }
19+ ] ,
1820 bootstrap : [ AppComponent ]
1921} )
2022export class AppModule { }
Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ export const authCodeFlowConfig: AuthConfig = {
77 responseType : 'code' ,
88 scope : 'openid profile email offline_access api' ,
99 showDebugInformation : true ,
10+ timeoutFactor : 0.01 ,
1011} ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { JwksValidationHandler } from 'angular-oauth2-oidc';
1414} )
1515export class AppComponent {
1616 constructor ( private router : Router , private oauthService : OAuthService ) {
17-
17+
1818 // Remember the selected configuration
1919 if ( sessionStorage . getItem ( 'flow' ) === 'code' ) {
2020 this . configureCodeFlow ( ) ;
@@ -43,15 +43,17 @@ export class AppComponent {
4343
4444
4545 private configureImplicitFlow ( ) {
46+
4647 this . oauthService . configure ( authConfig ) ;
4748 // this.oauthService.setStorage(localStorage);
4849 this . oauthService . tokenValidationHandler = new JwksValidationHandler ( ) ;
49- this . oauthService . loadDiscoveryDocumentAndTryLogin ( ) ;
5050
51+ this . oauthService . loadDiscoveryDocumentAndTryLogin ( ) ;
5152
5253 // Optional
5354 this . oauthService . setupAutomaticSilentRefresh ( ) ;
5455
56+
5557 // Display all events
5658 this . oauthService . events . subscribe ( e => {
5759 // tslint:disable-next-line:no-console
You can’t perform that action at this time.
0 commit comments