如何设置 Azure Authentication 自定义登录返回 url? [英] How to set Azure Authentication custom login return url?

查看:17
本文介绍了如何设置 Azure Authentication 自定义登录返回 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了这篇文章 https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/ 为我的 MVC 应用程序设置 Azure 身份验证.首先,我打开了 Azure AD 提供程序.在身份验证/授权设置中,我为请求未通过身份验证时采取的操作"选择了允许请求(无操作)",因为我只需要用户登录某些控制器操作.

I followed this article https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/ to set up Azure authentication for my MVC app. First I turned on Azure AD provider. In the Authentication / Authorization settings, I selected "Allow request(no Action)" for "Action to take when request is not authenticated" because I only need users to login for certain controller actions.

然后我添加了一个自定义 FilterAttribute 来检查一个操作是否需要身份验证,如 https://stackoverflow.com/a/26652816/1837339.在 OnAuthenticationChallenge 函数中,我将这段代码重定向到登录页面:

Then I added a custom FilterAttribute to check if one action needs authentication as in https://stackoverflow.com/a/26652816/1837339. In the OnAuthenticationChallenge function, I had this code to redirect to login page:

public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
    if (filterContext.Result is HttpUnauthorizedResult) {
        filterContext.Result = new RedirectResult("~/.auth/login/aad");
    }
}

所有这些都有效,除了用户完成身份验证后,它会被重定向回 mysite/.auth/login/done 页面,显示您已成功登录"和一个返回我网站的基本 URL 的按钮.

All of this works, except after user finished authentication, it is redirected back to mysite/.auth/login/done page saying "You have successfully signed in" and a button to return to my site's base url.

我想要的是重定向回到用户的原始 url,所以我想我需要以某种方式为登录重定向设置返回 url.但我找不到任何关于此的文档.谁能给点建议?

What I want is the redirection goes back to the user's original url, so I think I need somehow set the return url for the login redirect. But I couldn't find any documentation about this. Anyone could give any advice?

推荐答案

您可以使用 post_login_redirect_url 查询字符串参数来执行此操作.

You can use the post_login_redirect_url query string parameter to do this.

例如,如果您想在用户登录后自动导航到 /welcome.html,您可以将登录重定向设置为 ~/.auth/login/aad?post_login_redirect_url=/welcome.html,用户将被重定向到此页面而不是通用欢迎页面.

For example, if you want to automatically navigate the user to /welcome.html after logging in, you can set your login redirect to ~/.auth/login/aad?post_login_redirect_url=/welcome.html, and the user will be redirected to this page instead of the generic welcome page.

这篇关于如何设置 Azure Authentication 自定义登录返回 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆