Открытый идентификатор не перенаправляет на правильную страницу входа - PullRequest
0 голосов
/ 11 ноября 2019

Я последовал примеру 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"];
  }


}

при вызове функции login , которую он перенаправляет на страницу, которая требует Хмм, вы либо использовали неверные данные для входаили еще не зарегистрировались , но его предполагается перенаправить на страницу входа в систему, так как я вызвал
this.oauthService.initImplicitFlow (); .

его перенаправлениедо https://my -identity-domain.azurewebsites.net / идентичность / соединение / авторизированным? response_type = id_token% 20token & client_id = XXXXXXXXXXXXX & состояние = Psh7Ihio8Tv-JzrmG1ScmoZhB47SsjO-PqQoxyX0vhwbL & redirect_uri = HTTP% 3A% 2F% 2Flocalhost% 3A4200% 2Findex.html & Объем =openid% 20profile% 20email% 20roles% 20xxxxxxx% 20xxxxxxxx & nonce = Psh7Ihio8Tv-JzrmG1ScmoZhB47SsjO-PqQoxyX0vhwbL

, но веб-формы перенаправляются на * 10 * **

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

меня беспокоит то, что в веб-приложении asp.net оно работает, нона угловой версии новое разрабатываемое приложение не прошло три дня, пробуя много примеров в Интернете, что я могу сделать ??

я также попробовал https://github.com/manfredsteyer/angular-oauth2-oidc и использовал учетные данные там, это работало, но когда я заменяю на мое, оно не работает

...