带有 Azure AD 的 Spring Security 不会重定向 [英] Spring Security with Azure AD doesn't redirect

查看:80
本文介绍了带有 Azure AD 的 Spring Security 不会重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本指南使用 Azure AD 设置安全性 -

您需要在门户中将重定向 URL 设置为 http://localhost:8080/login/oauth2/code/azure.确保权限也已配置并获得管理员同意.

如果要更改重定向网址,需要在application.properties中添加spring.security.oauth2.client.registration.azure.redirect-uri-templatestrong> 并在门户中设置重定向 URL.

I follow this guide to setup Security with Azure AD - https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory

After login to Microsoft account system redirects me to url like this https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=25802571-a250-4e99-ba72-87c6eee9f1db&scope=openid%20https://graph.microsoft.com/user.read&state=0HA8WfPariUK8QXcwMlOseVIPNVm0f4XSa_T7JZZvyE%3D&redirect_uri=http://localhost:8079/login/oauth2/code/azure&nonce=eREVP5yO5L3WvOXH6HJfb_LAT8Gk7iu6jrdu259RePM but this url doesn't redirects me to my server

UPDATE 1: I turn on debug logs and on redirect I can see below logs in console

2020-10-08 22:39:59.700 DEBUG 756 --- [onPool-worker-9] c.m.a.m.ConfidentialClientApplication    : [Correlation ID: 7e63aac3-6ace-46e6-ab45-9c86aadfeed6] Access Token was returned
2020-10-08 22:40:01.542 DEBUG 756 --- [onPool-worker-9] c.m.a.m.ConfidentialClientApplication    : [Correlation ID: 712291cd-969f-4158-b26e-4b00aadfeed6] Access Token was returned
2020-10-08 22:40:02.762 DEBUG 756 --- [onPool-worker-9] c.m.a.m.ConfidentialClientApplication    : [Correlation ID: fafb0b37-254c-4e8d-bf15-ec5faadfeed6] Access Token was returned

解决方案

I try the spring boot sample, and it works well. It redirects to http://localhost:8080/ after login with the test user.

You need to set the redirect URL as http://localhost:8080/login/oauth2/code/azure in the portal. Make sure the permissions are also configured and granted admin consent.

If you want to change the redirect URL, you need to add spring.security.oauth2.client.registration.azure.redirect-uri-template in the application.properties and set the redirect URL in the portal.

这篇关于带有 Azure AD 的 Spring Security 不会重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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