Skip to content

Commit ca29cb9

Browse files
author
NEXUS\Anthony.Giretti
committed
remove useless code and implement
1 parent b8377aa commit ca29cb9

17 files changed

+70
-280
lines changed

.angular-cli.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
"assets": [
1111
"assets",
1212
"favicon.ico",
13-
"keys.json",
14-
"web.config",
15-
"silent-refresh.html",
16-
"oidc-client.min.js"
13+
"web.config"
1714
],
1815
"index": "index.html",
1916
"main": "main.ts",

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
"@angular/platform-browser": "^5.2.0",
2222
"@angular/platform-browser-dynamic": "^5.2.0",
2323
"@angular/router": "^5.2.0",
24-
"babel-polyfill": "^6.26.0",
2524
"classlist.js": "^1.1.20150312",
2625
"core-js": "^2.4.1",
27-
"oidc-client": "^1.4.1",
2826
"rxjs": "^5.5.6",
2927
"zone.js": "^0.8.19"
3028
},

src/app/app.module.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { AppComponent } from './app.component';
99

1010
import { ProtectedComponent } from './protected/protected.component';
1111
import { AuthCallbackComponent } from './auth-callback/auth-callback.component';
12-
import { SilentRefreshComponent } from './silentrefresh/silentrefresh.component';
12+
import { Adal5Service, Adal5HTTPService } from 'adal-angular5';
13+
import { HttpClient } from '@angular/common/http';
1314

1415
const routes: Routes = [
1516
{
@@ -25,26 +26,20 @@ const routes: Routes = [
2526
path: 'auth-callback',
2627
component: AuthCallbackComponent
2728
}
28-
,
29-
{
30-
path: 'silentrefresh',
31-
component: SilentRefreshComponent
32-
}
3329
];
3430

3531
@NgModule({
3632
declarations: [
3733
AppComponent,
3834
ProtectedComponent,
39-
AuthCallbackComponent,
40-
SilentRefreshComponent
35+
AuthCallbackComponent
4136
],
4237
imports: [
4338
BrowserModule,
4439
RouterModule.forRoot(routes)
4540
],
4641
exports: [RouterModule],
47-
providers: [AuthGuardService, AuthService],
42+
providers: [AuthGuardService, AuthService, Adal5Service,{ provide: Adal5HTTPService, useFactory: Adal5HTTPService.factory, deps: [HttpClient, Adal5Service] } ],
4843
bootstrap: [AppComponent]
4944
})
5045
export class AppModule { }
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
<p>
2-
auth-callback works!
3-
</p>

src/app/auth-callback/auth-callback.component.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ export class AuthCallbackComponent implements OnInit {
1414
ngOnInit() {
1515

1616

17-
console.log(document.location.href);
17+
this._authService.completeAuthentication();
1818

19-
20-
this._authService.completeAuthentication().then(() => {
21-
this._zone.run(
22-
() => this._router.navigate(['/protected'])
23-
);
24-
});
19+
setTimeout(() => {this._zone.run(
20+
() => this._router.navigate(['/protected'])
21+
);},200);
22+
2523
}
26-
2724
}

src/app/openIdConnectConfig.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
import { UserManagerSettings } from "oidc-client";
1+
// import { UserManagerSettings } from "oidc-client";
22

3-
export function getClientSettings(): UserManagerSettings {
4-
return {
5-
authority: 'https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679',
6-
client_id: '257b6c36-1168-4aac-be93-6f2cd81cec43',
7-
redirect_uri: 'http://localhost:4200/auth-callback',
8-
//redirect_uri: 'https://demoazureadconnectangular5.azurewebsites.net/auth-callback',
9-
post_logout_redirect_uri: 'http://localhost:4200/',
10-
//post_logout_redirect_uri: 'https://demoazureadconnectangular5.azurewebsites.net/',
11-
response_type:"id_token",
12-
scope:"openid profile",
13-
filterProtocolClaims: true,
14-
loadUserInfo: true,
15-
automaticSilentRenew: true,
16-
clockSkew: 0,
17-
accessTokenExpiringNotificationTime: 570,
18-
silent_redirect_uri: 'http://localhost:4200/silent-refresh.html',
19-
metadata: {
20-
issuer: "https://sts.windows.net/136544d9-038e-4646-afff-10accb370679/",
21-
authorization_endpoint: "https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679/oauth2/authorize",
22-
token_endpoint: "https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679/oauth2/token",
23-
//jwks_uri: "https://login.microsoftonline.com/common/discovery/keys",
24-
jwks_uri: "http://localhost:4200/assets/keys.json",
25-
//jwks_uri: "https://demoazureadconnectangular5.azurewebsites.net/assets/keys.json",
26-
//jwks_uri: "http://localhost:50586/api/keys",
27-
signingKeys: [{"ApiAccessKey": "NgixniZ0S1JHxo7GPEZYa38OBTxSA98AqJKDX5XqsJ8="}]
28-
}
29-
};
30-
}
3+
// export function getClientSettings(): UserManagerSettings {
4+
// return {
5+
// authority: 'https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679',
6+
// client_id: '257b6c36-1168-4aac-be93-6f2cd81cec43',
7+
// redirect_uri: 'http://localhost:4200/auth-callback',
8+
// //redirect_uri: 'https://demoazureadconnectangular5.azurewebsites.net/auth-callback',
9+
// post_logout_redirect_uri: 'http://localhost:4200/',
10+
// //post_logout_redirect_uri: 'https://demoazureadconnectangular5.azurewebsites.net/',
11+
// response_type:"id_token",
12+
// scope:"openid profile",
13+
// filterProtocolClaims: true,
14+
// loadUserInfo: true,
15+
// automaticSilentRenew: true,
16+
// clockSkew: 0,
17+
// silent_redirect_uri: 'http://localhost:4200/silent-refresh.html',
18+
// metadata: {
19+
// issuer: "https://sts.windows.net/136544d9-038e-4646-afff-10accb370679/",
20+
// authorization_endpoint: "https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679/oauth2/authorize",
21+
// token_endpoint: "https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679/oauth2/token",
22+
// //jwks_uri: "https://login.microsoftonline.com/common/discovery/keys",
23+
// jwks_uri: "http://localhost:4200/assets/keys.json",
24+
// //jwks_uri: "https://demoazureadconnectangular5.azurewebsites.net/assets/keys.json",
25+
// //jwks_uri: "http://localhost:50586/api/keys",
26+
// signingKeys: [{"ApiAccessKey": "NgixniZ0S1JHxo7GPEZYa38OBTxSA98AqJKDX5XqsJ8="}]
27+
// }
28+
// };
29+
// }

src/app/protected/protected.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55

66

7-
<iframe id="test" name="frame1" src="https://login.microsoftonline.com/136544d9-038e-4646-afff-10accb370679/oauth2/authorize?client_id=257b6c36-1168-4aac-be93-6f2cd81cec43&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth-callback&response_type=id_token&scope=openid%20profile&state=1d56619048f94af587af8e35529735d1&nonce=89ddb46c69c047caa26fdc44a938eb45&prompt=none"></iframe>
7+
<a href="javascript:void(0);" (click)="signout();">signout</a>

src/app/protected/protected.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ export class ProtectedComponent implements OnInit {
1212
constructor(private _authService: AuthService) { }
1313

1414
ngOnInit() {
15-
console.log(this._authService.isLoggedIn());
16-
console.log(this._authService.getUser());
1715
this.name = this._authService.getName();
18-
19-
this._authService.subscribeevents();
2016
}
2117

18+
public signout(): void {
19+
this._authService.signout();
20+
}
2221
}

src/app/services/auth-guard.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { AuthService } from './auth.service';
22
import { Injectable } from '@angular/core';
3-
import { UserManager, UserManagerSettings, User } from 'oidc-client';
43
import { CanActivate } from '@angular/router';
54

65
@Injectable()

src/app/services/auth.service.ts

Lines changed: 28 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,52 @@
1-
import { UserManagerSettings, UserManager, User } from 'oidc-client';
21
import { Injectable } from '@angular/core';
3-
import { getClientSettings } from '../openIdConnectConfig';
2+
import { Adal5Service, Adal5HTTPService } from 'adal-angular5';
3+
import { adal } from 'adal-angular';
4+
import { HttpClient, HttpHandler } from '@angular/common/http';
5+
import { Observable } from 'rxjs/Observable';
6+
7+
const config: adal.Config = {
8+
tenant: '136544d9-038e-4646-afff-10accb370679',
9+
clientId: '257b6c36-1168-4aac-be93-6f2cd81cec43',
10+
redirectUri: "https://demoazureadconnectangular5.azurewebsites.net/auth-callback",
11+
postLogoutRedirectUri: "https://demoazureadconnectangular5.azurewebsites.net"
12+
}
413

514
@Injectable()
615
export class AuthService {
716

8-
private _manager = new UserManager(getClientSettings());
9-
private _user: User = null;
17+
private _user = null;
1018

11-
constructor() {
12-
13-
// this._manager.getUser().then(user => {
14-
// var token = this.parseJwt(user.id_token);
15-
// user.expires_at = token.exp;
16-
// console.log(user.expires_at);
17-
// this._user = user;
18-
// });
19-
20-
this._manager.events.addUserLoaded(user => {
21-
var token = this.parseJwt(user.id_token);
22-
user.expires_at = token.exp;
23-
console.log(user.expires_at);
24-
this._user = user;
25-
var that = this;
26-
this.subscribeevents();
27-
});
28-
29-
//
30-
19+
constructor(private _adal: Adal5Service) {
3120

3221
}
3322

3423
public isLoggedIn(): boolean {
35-
return this._user != null && !this._user.expired;
24+
return this._adal.userInfo.authenticated;
3625
}
37-
38-
public getClaims(): any {
39-
return this._user.profile;
26+
27+
signout(): any {
28+
this._adal.logOut();
4029
}
4130

42-
public subscribeevents() :void {
43-
this._manager.events.addSilentRenewError(() => {
44-
console.log("error SilentRenew");
45-
});
46-
47-
this._manager.events.addAccessTokenExpiring(() => {
48-
console.log("access token expiring");
49-
});
50-
51-
this._manager.events.addAccessTokenExpired(() => {
52-
console.log("access token expired");
53-
});
31+
startAuthentication(): any {
32+
this._adal.init(config);
33+
this._adal.login();
5434
}
5535

56-
public refreshCallBack(): void
57-
{
58-
console.log("start refresh callback");
59-
this._manager.signinSilentCallback()
60-
.then(data => {console.log("suucess callback")})
61-
.catch(err => {
62-
console.log("err callback");
63-
});
64-
console.log("end refresh callback");
65-
}
36+
getName(): string {
6637

67-
getUser(): any {
68-
return this._user;
69-
}
70-
71-
getName(): any {
7238
return this._user.profile.name;
7339
}
7440

75-
getAuthorizationHeaderValue(): string {
76-
return `${this._user.token_type} ${this._user.access_token}`;
77-
}
7841

79-
startAuthentication(): Promise<void> {
80-
return this._manager.signinRedirect();
81-
}
8242

83-
completeAuthentication(): Promise<void> {
84-
return this._manager.signinRedirectCallback().then(user => {
85-
this._user = user;
43+
completeAuthentication(): any {
44+
this._adal.handleWindowCallback();
45+
return this._adal.getUser().subscribe(user => {
46+
this._user = user;
47+
console.log(user);
48+
var expireIn = user.profile.exp - new Date().getTime();
49+
//redirectCallBack();
8650
});
87-
88-
89-
}
90-
91-
parseJwt (token) {
92-
var base64Url = token.split('.')[1];
93-
var base64 = base64Url.replace('-', '+').replace('_', '/');
94-
return JSON.parse(window.atob(base64));
95-
};
96-
97-
98-
public Call()
99-
{
100-
//this._http.
10151
}
102-
10352
}

src/app/silentrefresh/silentrefresh.component.css

Whitespace-only changes.

src/app/silentrefresh/silentrefresh.component.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/app/silentrefresh/silentrefresh.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/app/silentrefresh/silentrefresh.component.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/assets/keys.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/assets/oidc-client.min.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/assets/silent-refresh.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)