c# - 打开 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/login?signin=xxxxxxxxxxxxxx
让我担心的是,在 asp.net webform 应用程序中它可以工作,但在 angular 版本中,正在开发的新应用程序不是三天在网上尝试了很多示例我能做什么?
我也尝试过https://github.com/manfredsteyer/angular-oauth2-oidc并在那里使用了凭据,但是当我用我的替换它时它不起作用
解决方案
推荐阅读
- python - 如何从python列表中删除停用词
- android - 使用 Amazon Cognito 的推荐邀请
- node.js - 如何将函数存储在 MongoDb 文档中,然后从那里读取并调用它?
- gimp - 像素区域比较
- spring - 值未显示到 Spring MVC 视图中
- javascript - 如何从另一个父道具获得道具?
- java - 升级 Java 和 Eclipse 版本
- c++ - 为什么该文件中的数据没有正确写入/读取?
- javascript - jQuery 库与内联脚本冲突
- javascript - NodeJS Express - GET/POST/PATCH/DELETE 在幕后的区别