SPA: identity component
This commit is contained in:
parent
fa20099a16
commit
bced5f0a33
@ -7,8 +7,8 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<esh-identity></esh-identity>
|
||||
<esh-basket-status *ngIf="Authenticated"></esh-basket-status>
|
||||
<esh-identity *ngIf="!Authenticated"></esh-identity>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1 +1,2 @@
|
||||
<button (click)="login()">Login</button>
|
||||
<button *ngIf="!authenticated" (click)="login()">Login</button>
|
||||
<div *ngIf="authenticated">userName: {{userName}}</div>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Component, OnInit, OnChanges, Output, Input, EventEmitter } from '@angular/core';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
import { IIdentity } from '../../models/identity.model';
|
||||
import { SecurityService } from '../../services/security.service';
|
||||
@ -9,22 +10,26 @@ import { SecurityService } from '../../services/security.service';
|
||||
styleUrls: ['./identity.scss']
|
||||
})
|
||||
export class Identity implements OnInit {
|
||||
private authenticated: boolean = false;
|
||||
private subscription: Subscription;
|
||||
private userName: string = "";
|
||||
|
||||
constructor(private service: SecurityService) {
|
||||
|
||||
}
|
||||
|
||||
@Output()
|
||||
changed: EventEmitter<number> = new EventEmitter<number>();
|
||||
|
||||
@Input()
|
||||
model: IIdentity;
|
||||
|
||||
ngOnInit() {
|
||||
console.log("ngOnInit _securityService.AuthorizedCallback");
|
||||
this.subscription = this.service.authenticationChallenge$.subscribe(res =>
|
||||
{
|
||||
//console.log(res);
|
||||
//console.log(this.service.UserData);
|
||||
//console.log(this.service);
|
||||
this.authenticated = res;
|
||||
this.userName = this.service.UserData.email;
|
||||
});
|
||||
|
||||
if (window.location.hash) {
|
||||
this.service.AuthorizedCallback();
|
||||
console.log('isAutorized?');
|
||||
console.log(this.service.IsAuthorized);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,22 +16,17 @@ export class SecurityService {
|
||||
authenticationChallenge$ = this.authenticationSource.asObservable();
|
||||
|
||||
constructor(private _http: Http, private _router: Router) {
|
||||
|
||||
//this.actionUrl = _configuration.Server + 'api/DataEventRecords/';
|
||||
|
||||
this.headers = new Headers();
|
||||
this.headers.append('Content-Type', 'application/json');
|
||||
this.headers.append('Accept', 'application/json');
|
||||
this.storage = sessionStorage; //localStorage;
|
||||
|
||||
if (this.retrieve("IsAuthorized") !== "") {
|
||||
//this.HasAdminRole = this.retrieve("HasAdminRole");
|
||||
this.IsAuthorized = this.retrieve("IsAuthorized");
|
||||
}
|
||||
}
|
||||
|
||||
public IsAuthorized: boolean;
|
||||
//public HasAdminRole: boolean;
|
||||
|
||||
public GetToken(): any {
|
||||
return this.retrieve("authorizationData");
|
||||
@ -42,8 +37,6 @@ export class SecurityService {
|
||||
this.store("authorizationDataIdToken", "");
|
||||
|
||||
this.IsAuthorized = false;
|
||||
//this.HasAdminRole = false;
|
||||
this.store("HasAdminRole", false);
|
||||
this.store("IsAuthorized", false);
|
||||
}
|
||||
|
||||
@ -57,11 +50,13 @@ export class SecurityService {
|
||||
this.store("authorizationDataIdToken", id_token);
|
||||
this.IsAuthorized = true;
|
||||
this.store("IsAuthorized", true);
|
||||
//emit observable
|
||||
this.authenticationSource.next(true);
|
||||
|
||||
this.getUserData()
|
||||
.subscribe(data => this.UserData = data,
|
||||
.subscribe(data => {
|
||||
this.UserData = data;
|
||||
//emit observable
|
||||
this.authenticationSource.next(true);
|
||||
},
|
||||
error => this.HandleError(error),
|
||||
() => {
|
||||
console.log(this.UserData);
|
||||
@ -71,8 +66,6 @@ export class SecurityService {
|
||||
public Authorize() {
|
||||
this.ResetAuthorizationData();
|
||||
|
||||
console.log("BEGIN Authorize, no auth data");
|
||||
|
||||
var authorizationUrl = 'http://localhost:5105/connect/authorize';
|
||||
var client_id = 'js';
|
||||
var redirect_uri = 'http://localhost:5104/';
|
||||
@ -83,7 +76,6 @@ export class SecurityService {
|
||||
|
||||
this.store("authStateControl", state);
|
||||
this.store("authNonce", nonce);
|
||||
console.log("AuthorizedController created. adding myautostate: " + this.retrieve("authStateControl"));
|
||||
|
||||
var url =
|
||||
authorizationUrl + "?" +
|
||||
@ -98,7 +90,6 @@ export class SecurityService {
|
||||
}
|
||||
|
||||
public AuthorizedCallback() {
|
||||
console.log("BEGIN AuthorizedCallback, no auth data");
|
||||
this.ResetAuthorizationData();
|
||||
|
||||
var hash = window.location.hash.substr(1);
|
||||
@ -110,7 +101,6 @@ export class SecurityService {
|
||||
}, {});
|
||||
|
||||
console.log(result);
|
||||
console.log("AuthorizedCallback created, begin token validation");
|
||||
|
||||
var token = "";
|
||||
var id_token = "";
|
||||
|
@ -39,8 +39,8 @@
|
||||
},
|
||||
"tools": {
|
||||
"Microsoft.DotNet.Watcher.Tools": {
|
||||
"version": "1.0.0-*",
|
||||
"imports": "portable-net451+win8"
|
||||
"version": "1.0.0-preview2-final",
|
||||
"imports": "portable-net451+win8+dnxcore50"
|
||||
},
|
||||
"Microsoft.AspNetCore.Razor.Tools": {
|
||||
"version": "1.0.0-preview2-final",
|
||||
|
Loading…
x
Reference in New Issue
Block a user