當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript OAuthService.setStorage方法代碼示例

本文整理匯總了TypeScript中angular2-oauth2/oauth-service.OAuthService.setStorage方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OAuthService.setStorage方法的具體用法?TypeScript OAuthService.setStorage怎麽用?TypeScript OAuthService.setStorage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在angular2-oauth2/oauth-service.OAuthService的用法示例。


在下文中一共展示了OAuthService.setStorage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

    constructor(private oauthService: OAuthService, private router: Router) {

        this.oauthService.loginUrl = "https://steyer-identity-server.azurewebsites.net/identity/connect/authorize"; //Id-Provider?
        this.oauthService.logoutUrl = "https://steyer-identity-server.azurewebsites.net/identity/connect/endsession?id_token={{id_token}}";
        this.oauthService.redirectUri = window.location.origin + "/home";
        this.oauthService.clientId = "spa-demo";
        this.oauthService.scope = "openid profile email voucher";
        this.oauthService.issuer = "https://steyer-identity-server.azurewebsites.net/identity";
        this.oauthService.oidc = true;
        this.oauthService.setStorage(localStorage);
        
        this.oauthService.tryLogin({});

    
    }
開發者ID:yooynas,項目名稱:angular-2-rc4-router-sample-oauth,代碼行數:15,代碼來源:app.component.ts

示例2: function

app.run(function(
    oauthService: OAuthService,
    $state,
    $rootScope: angular.IRootScopeService,
    $http: angular.IHttpService) {



    // oauthService.loginUrl = "https://steyer-identity-server.azurewebsites.net/identity/connect/authorize"; //Id-Provider?
    // oauthService.issuer = "https://steyer-identity-server.azurewebsites.net/identity";

    oauthService.loginUrl = "https://localhost:44301/identity/connect/authorize"; //Id-Provider?
    oauthService.issuer = "https://localhost:44301/identity";


        oauthService.redirectUri = window.location.origin + "/index.html";
    oauthService.clientId = "spa-demo";

    oauthService.scope = "openid profile email voucher";
    oauthService.oidc = true;
    oauthService.setStorage(sessionStorage);

    oauthService.tryLogin({
        onTokenReceived: (ctx) => {
            $http.defaults.headers.common['Authorization'] = 'Bearer ' + oauthService.getAccessToken();
        }
    });


    $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 });
        }

    });

})
開發者ID:CodebustersMarcel,項目名稱:full,代碼行數:47,代碼來源:app.ts

示例3: 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);
    }
  }
開發者ID:cackharot,項目名稱:fbeazt,代碼行數:41,代碼來源:app.component.ts


注:本文中的angular2-oauth2/oauth-service.OAuthService.setStorage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。