首页 > 解决方案 > 打开 id 未重定向到正确的登录页面

问题描述

我在这里按照示例 https://www.softwarearchitekt.at/aktuelles/authentication-in-angular-2-with-oauth2-oidc/ 使用了相同的登录详细信息。

除了他们提供的配置和 url 员工之外,我无权访问受支持的员工。

当我尝试执行以下相同操作时

import { Component, OnInit } from '@angular/core';
import { OAuthService, JwksValidationHandler, AuthConfig } from 'angular-oauth2-oidc';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})


export class LoginComponent implements OnInit {

   config  : AuthConfig;
  constructor(private oauthService: OAuthService) {
    this.config = new AuthConfig();

   /*
 this.config.loginUrl  = "https://my-identity-domain.azurewebsites.net/connect/authorize"; 
    this.config.clientId = "xxxxxxxxxx";
    this.config.redirectUri = window.location.origin + '/home';
    this.config.scope = "openid profile email ccxxxxx";
    this.config.responseType = 'code';

   */
  this.config.issuer =  'https://my-identity-domain.azurewebsites.net/identity';

  // URL of the SPA to redirect the user to after login window.location.origin + '/login'
  this.config.redirectUri = window.location.origin + "/login";

  // The SPA's id. The SPA is registered with this id at the auth-server
  this.config.clientId = 'xxxxxxxxx';

   // Use setStorage to use sessionStorage or another implementation of the TS-type Storage
    // instead of localStorage
    this.oauthService.setStorage(sessionStorage);

    // set to true, to receive also an id_token via OpenId Connect (OIDC) in addition to the
    // OAuth2-based access_token
    this.oauthService.oidc = true; // ID_Token

  // set the scope for the permissions the client should request 
  // The first three are defined by OIDC. The 4th is a usecase-specific one
  this.config.scope = 'openid profile email roles xxxxx';

//  this.config.responseType = 'code';

  }

  ngOnInit() {
  }
  private ConfigureImplicitFlowAuthentication() {


    this.oauthService.configure(this.config);

      this.oauthService.tokenValidationHandler = new JwksValidationHandler();
      const url = 'https://my-identity-domain.azurewebsites.net/identity/.well-known/openid-configuration';
      this.oauthService.loadDiscoveryDocument(url).then((doc) => {
        this.oauthService.tryLogin({})
            .catch(err => {
                console.error(err);
            })
            .then(() => {
                if(!this.oauthService.hasValidAccessToken()) {
          console.log("Implicit flow has been called initImplicitFlow "); 
                    this.oauthService.initImplicitFlow();
                }
            });
      });
  }

  private configure() { 
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    const url = 'https://my-identity-domain.azurewebsites.net/identity/.well-known/openid-configuration';   
    this.oauthService.loadDiscoveryDocument(url);
    this.oauthService.initLoginFlow();
  }
  public login() {



       console.log('configured open id' , this.config);
       this.oauthService.configure(this.config);
       this.ConfigureImplicitFlowAuthentication();
      // this.configure();


       //this.oauthService.initImplicitFlow();
//       this.ConfigureImplicitFlowAuthentication();

       /*

       this.oauthService.loadDiscoveryDocument(url).then((doc) => {
         console.log('loaded doc 123-  : ' , doc);
         this.oauthService.tryLogin()
         .catch(err => {
           console.error(err);
         })
         .then(() => {
           if(!this.oauthService.hasValidAccessToken()) {
             this.oauthService.initImplicitFlow()
           }
         });
         console.debug('discovery succeeded', doc);
       });

        */
       console.log('opein id failed');
       //this.oauthService.events.subscribe(e => e instanceof OAuthErrorEvent ? console.error(e) : console.warn(e));

       // Load information from Auth0 (could also be configured manually)
       //this.ConfigureImplicitFlowAuthentication();
  }

  public logoff() {
      this.oauthService.logOut();
  }

  public get name() {
      let claims = this.oauthService.getIdentityClaims();
      if (!claims) return null;
      console.log("claim object");
      console.log(claims);
      return claims["given_name"];
  }


}

在调用登录功能时,它会重定向到需要说的页面嗯,您要么使用了不正确的登录详细信息,要么尚未注册,但它假设被重定向到登录页面,因为我调用
了 this.oauthService.initImplicitFlow() ; .

其重定向到 https://my-identity-domain.azurewebsites.net/identity/connect/authorize?response_type=id_token%20token&client_id=xxxxxxxxxxxxx&state=Psh7Ihio8Tv-JzrmG1ScmoZhB47SsjO-PqQoxyX0vhwbL&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Findex.html&scope =openid%20profile%20email%20roles%20xxxxxxx%20xxxxxxxx&nonce=Psh7Ihio8Tv-JzrmG1ScmoZhB47SsjO-PqQoxyX0vhwbL

但网络表单正在重定向到

https://my-identity-domain.azurewebsites.net/identity/login?signin=xxxxxxxxxxxxxx

让我担心的是,在 asp.net webform 应用程序中它可以工作,但在 angular 版本中,正在开发的新应用程序不是三天在网上尝试了很多示例我能做什么?

我也尝试过https://github.com/manfredsteyer/angular-oauth2-oidc并在那里使用了凭据,但是当我用我的替换它时它不起作用

标签: c#angularauthenticationopenidangular-oauth2-oidc

解决方案


推荐阅读