Dou*_*son 4 c# asp.net-mvc owin
我正在使用 OWIN 通过 ASP.NET MVC 应用程序中的 Microsoft Graph API 连接到 O365。一切都在 Startup.Auth.cs 中设置,包括当前来自 web.config 的 Redirect Uri 值。身份验证工作正常。
由于我在应用程序注册中使用通配符,因此重定向 uri 可以是各种值,并且用户可以从应用程序中的任意数量的页面向 O365 进行身份验证。一旦通过身份验证,我希望它们被带回他们刚刚所在的页面,但因为重定向 uri 已经设置,它们被带回该页面。
创建 OWIN 标识上下文后,如何修改代码中其他位置的重定向 uri?
下面是启动代码的片段。
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
private static string redirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"];
....
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = appId,
Authority = "https://login.microsoftonline.com/organizations/v2.0",
PostLogoutRedirectUri = redirectUri,
RedirectUri = redirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async (context) =>
{
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("client_id", appId);
data.Add("client_secret", appSecret);
data.Add("code", code);
data.Add("grant_type", "authorization_code");
data.Add("redirect_uri", redirectUri);
...
Run Code Online (Sandbox Code Playgroud)
我也有类似的情况。我绑定到 RedirectToIdentityProvider,在向身份提供者发送请求之前修改 RedirectUri。类似于以下内容
Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = async (context) =>
{
context.ProtocolMessage.RedirectUri = "Whatever_You_Want_Here";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2186 次 |
| 最近记录: |