本文整理匯總了TypeScript中angular2-oauth2/oauth-service.OAuthService.hasValidAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OAuthService.hasValidAccessToken方法的具體用法?TypeScript OAuthService.hasValidAccessToken怎麽用?TypeScript OAuthService.hasValidAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2-oauth2/oauth-service.OAuthService
的用法示例。
在下文中一共展示了OAuthService.hasValidAccessToken方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: canActivate
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
var hasIdToken = this.oauthService.hasValidIdToken();
var hasAccessToken = this.oauthService.hasValidAccessToken();
return (hasIdToken && hasAccessToken);
}
示例2: canActivate
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
var hasIdToken = this.oauthService.hasValidIdToken(); //ID --> who the user is
var hasAccessToken = this.oauthService.hasValidAccessToken(); // backend-service
return (hasIdToken && hasAccessToken);
}
開發者ID:manfredsteyer,項目名稱:angular2-router-angular_berlin-july-2017,代碼行數:9,代碼來源:flight-booking.guard.ts
示例3: canActivate
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
var hasIdToken = this.oauthService.hasValidIdToken(); // Who the user
var hasAccessToken = this.oauthService.hasValidAccessToken(); // access rest-service
return (hasIdToken && hasAccessToken);
}
示例4: function
$rootScope.$on("$stateChangeStart", function (event: angular.IAngularEvent, toState: IState, toParams, fromState: IState, fromParams) {
if (DEBUG) return;
let loggedIn = oauthService.hasValidAccessToken()
&& oauthService.hasValidIdToken();
if (toState.data && toState.data.protected && !loggedIn) {
event.preventDefault();
var requestedUrl = $state.href(toState, toParams);
$state.transitionTo("home", { requestedUrl: requestedUrl });
}
});
示例5: constructor
constructor(
private oauthService: OAuthService,
public feature: FeatureService,
private router: Router,
private http: Http) {
try {
this.oauthService.loginUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
this.oauthService.redirectUri = window.location.origin;
this.oauthService.clientId = '280436316587-pc2v79112kdqu0jiruu56m92s8nr4s42.apps.googleusercontent.com';
this.oauthService.scope = 'openid profile email';
this.oauthService.oidc = true;
this.oauthService.setStorage(sessionStorage);
this.oauthService.logoutUrl = null;
this.oauthService.tryLogin({
onTokenReceived: context => {
if (window.location.hash && window.location.hash.indexOf('access_token') !== -1) {
this.router.navigate(['home']);
}
},
validationHandler: context => {
let search = new URLSearchParams();
search.set('access_token', context.accessToken);
let v = http.get('https://www.googleapis.com/oauth2/v3/tokeninfo', { search })
.toPromise().then(x => {
if (x.json().aud !== oauthService.clientId) {
console.error('Wrong client_id');
oauthService.logOut();
}
});
return v;
}
});
if (!this.oauthService.hasValidAccessToken()) {
this.oauthService.logOut();
}
} catch (e) {
console.error(e);
}
}