|
@@ -16,7 +16,7 @@ export class TokenAuthService{
|
|
}
|
|
}
|
|
|
|
|
|
authenticate(authenticateModel:AuthenticateModel): Observable<AuthenticateResult> {
|
|
authenticate(authenticateModel:AuthenticateModel): Observable<AuthenticateResult> {
|
|
- let url = this.baseUrl + "/connect/token";
|
|
|
|
|
|
+ let url = "http://localhost:54225/api/identity";
|
|
|
|
|
|
return this.http.post<AuthenticateResult>(url, authenticateModel).pipe(
|
|
return this.http.post<AuthenticateResult>(url, authenticateModel).pipe(
|
|
tap(item => console.log("authenticate user")),
|
|
tap(item => console.log("authenticate user")),
|
|
@@ -35,12 +35,28 @@ export class TokenAuthService{
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
- return this.http.get<UserInfo>(url).pipe(
|
|
|
|
|
|
+ return this.http.get<UserInfo>(url,options_).pipe(
|
|
tap(item => console.log("authenticate user")),
|
|
tap(item => console.log("authenticate user")),
|
|
catchError(this.handleError<UserInfo>("authenticate user"))
|
|
catchError(this.handleError<UserInfo>("authenticate user"))
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ logout(): Observable<boolean> {
|
|
|
|
+ let url = "http://localhost:54225/api/identity";
|
|
|
|
+ let options_ = {
|
|
|
|
+ headers : new HttpHeaders({
|
|
|
|
+ "Content-Type": "application/json",
|
|
|
|
+ "Accept": "application/json",
|
|
|
|
+ "Authorization": "Bearer " + this.getCookie("auth_token")
|
|
|
|
+ })
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return this.http.delete<boolean>(url, options_).pipe(
|
|
|
|
+ tap(item => console.log("authenticate logout")),
|
|
|
|
+ catchError(this.handleError<boolean>("authenticate logout"))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
private getCookie(name) {
|
|
private getCookie(name) {
|
|
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
|
|
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
|
|
if (arr = document.cookie.match(reg)) {
|
|
if (arr = document.cookie.match(reg)) {
|
|
@@ -81,7 +97,7 @@ export class AuthenticateModel {
|
|
|
|
|
|
export class AuthenticateResult{
|
|
export class AuthenticateResult{
|
|
access_token: string;
|
|
access_token: string;
|
|
- expires_in: string;
|
|
|
|
|
|
+ expires_in: number;
|
|
token_type: string;
|
|
token_type: string;
|
|
}
|
|
}
|
|
|
|
|