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 34
34
"angular-oauth2-oidc-jwks" : " ^9.0.0" ,
35
35
"base64-js" : " ^1.3.0" ,
36
36
"bootstrap" : " ^3.3.7" ,
37
+ "js-sha256" : " ^0.9.0" ,
37
38
"jsrsasign" : " ^8.0.12" ,
38
39
"rxjs" : " 6.5.4" ,
39
40
"rxjs-compat" : " ^6.5.2" ,
Original file line number Diff line number Diff line change 6
6
},
7
7
"version" : " 9.0.1" ,
8
8
"repository" : " manfredsteyer/angular-oauth2-oidc" ,
9
+ "dependencies" : {
10
+ "js-sha256" : " ^0.9.0"
11
+ },
9
12
"peerDependencies" : {
10
13
"@angular/common" : " >=8.0.0" ,
11
14
"@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 {
1436
1436
public tryLogin ( options : LoginOptions = null ) : Promise < boolean > {
1437
1437
if ( this . config . responseType === 'code' ) {
1438
1438
return this . tryLoginCodeFlow ( options ) . then ( _ => true ) ;
1439
- }
1440
- else {
1439
+ } else {
1441
1440
return this . tryLoginImplicitFlow ( options ) ;
1442
1441
}
1443
1442
}
@@ -2243,6 +2242,12 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2243
2242
if ( crypto ) {
2244
2243
let bytes = new Uint8Array ( size ) ;
2245
2244
crypto . getRandomValues ( bytes ) ;
2245
+
2246
+ // Needed for IE
2247
+ if ( ! bytes . map ) {
2248
+ ( bytes as any ) . map = Array . prototype . map ;
2249
+ }
2250
+
2246
2251
bytes = bytes . map ( x => unreserved . charCodeAt ( x % unreserved . length ) ) ;
2247
2252
id = String . fromCharCode . apply ( null , bytes ) ;
2248
2253
} else {
Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
2
3
+ import { sha256 } from 'js-sha256' ;
4
+
5
+
3
6
/**
4
7
* Abstraction for crypto algorithms
5
8
*/
@@ -11,10 +14,23 @@ export abstract class HashHandler {
11
14
export class DefaultHashHandler implements HashHandler {
12
15
13
16
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 ;
18
34
}
19
35
20
36
toHashString ( buffer : ArrayBuffer ) {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export class AppComponent {
15
15
constructor ( private oauthService : OAuthService ) {
16
16
this . oauthService . configure ( authCodeFlowConfig ) ;
17
17
this . oauthService . loadDiscoveryDocumentAndLogin ( ) ;
18
+ this . oauthService . setupAutomaticSilentRefresh ( ) ;
18
19
19
20
// Automatically load user profile
20
21
this . oauthService
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
2
2
import { NgModule } from '@angular/core' ;
3
3
4
4
import { AppComponent } from './app.component' ;
5
- import { OAuthModule } from 'angular-oauth2-oidc' ;
5
+ import { OAuthModule , OAuthStorage } from 'angular-oauth2-oidc' ;
6
6
import { HttpClientModule } from '@angular/common/http' ;
7
7
8
8
@NgModule ( {
@@ -14,7 +14,9 @@ import { HttpClientModule } from '@angular/common/http';
14
14
declarations : [
15
15
AppComponent
16
16
] ,
17
- providers : [ ] ,
17
+ providers : [
18
+ { provide : OAuthStorage , useValue : localStorage }
19
+ ] ,
18
20
bootstrap : [ AppComponent ]
19
21
} )
20
22
export class AppModule { }
Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ export const authCodeFlowConfig: AuthConfig = {
7
7
responseType : 'code' ,
8
8
scope : 'openid profile email offline_access api' ,
9
9
showDebugInformation : true ,
10
+ timeoutFactor : 0.01 ,
10
11
} ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { JwksValidationHandler } from 'angular-oauth2-oidc';
14
14
} )
15
15
export class AppComponent {
16
16
constructor ( private router : Router , private oauthService : OAuthService ) {
17
-
17
+
18
18
// Remember the selected configuration
19
19
if ( sessionStorage . getItem ( 'flow' ) === 'code' ) {
20
20
this . configureCodeFlow ( ) ;
@@ -43,15 +43,17 @@ export class AppComponent {
43
43
44
44
45
45
private configureImplicitFlow ( ) {
46
+
46
47
this . oauthService . configure ( authConfig ) ;
47
48
// this.oauthService.setStorage(localStorage);
48
49
this . oauthService . tokenValidationHandler = new JwksValidationHandler ( ) ;
49
- this . oauthService . loadDiscoveryDocumentAndTryLogin ( ) ;
50
50
51
+ this . oauthService . loadDiscoveryDocumentAndTryLogin ( ) ;
51
52
52
53
// Optional
53
54
this . oauthService . setupAutomaticSilentRefresh ( ) ;
54
55
56
+
55
57
// Display all events
56
58
this . oauthService . events . subscribe ( e => {
57
59
// tslint:disable-next-line:no-console
You can’t perform that action at this time.
0 commit comments