Java Azure上带Active Directory的Spring OAuth2应用程序的重定向URL:无效的重定向URI参数
以下是Azure文档的两个教程: 它展示了如何将一个简单的Spring引导应用程序部署到Azure和 使用Spring Security OAuth2客户端设置并使用active directory作为OAuth2服务器。 基本上,我只是将OAuth2依赖项添加到Maven,这是一个WebSecurityConfig类,如第二个文档所示,另外还有azure.activedirectoy和spring.security属性 当应用程序刚从本地计算机运行时,登录和重定向工作正常。但是,当应用程序部署到Azure时,我得到一个应用程序错误,它说:无效的重定向URI参数。我想我已经将重定向uri正确设置为Java Azure上带Active Directory的Spring OAuth2应用程序的重定向URL:无效的重定向URI参数,java,azure,spring-boot,azure-active-directory,spring-security-oauth2,Java,Azure,Spring Boot,Azure Active Directory,Spring Security Oauth2,以下是Azure文档的两个教程: 它展示了如何将一个简单的Spring引导应用程序部署到Azure和 使用Spring Security OAuth2客户端设置并使用active directory作为OAuth2服务器。 基本上,我只是将OAuth2依赖项添加到Maven,这是一个WebSecurityConfig类,如第二个文档所示,另外还有azure.activedirectoy和spring.security属性 当应用程序刚从本地计算机运行时,登录和重定向工作正常。但是,当应用程序部署
https://{baseHost}{basePort}{basePath}/login/oauth2/code/azure
在应用程序属性中以及在我的Active Directory中注册的应用程序中
据我所知,授权请求使用了正确的参数:
response_type: code
client_id: 4b5fbcfd-c35f-4bab-bc45-374c7e1dead8
scope: openid https://graph.microsoft.com/user.read
state: yMvo62R-6vgjETSGr_mnh4iIMZimVnFYZRyiGFaOPtE=
redirect_uri: https://myappname.azurewebsites.net/login/oauth2/code/azure
nonce: FUXJ5GoJ2NuNVx2ORU70YCqnJkEj8FRYHEJYMutEQzo
那么,无效的重定向URI参数可能是什么,我如何更改它?我遵循了这两个教程,它在本地环境下运行良好,在Azure webapp上,我遇到了重定向url不匹配错误 原因是重定向uri总是以http启动。在applications.properties中添加
server.forward headers strategy=native
后,它可以工作。(我使用的是spring boot 2.2)
以下是pom.xml供您参考
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example.ad</groupId>
<artifactId>ad</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ad</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<azure.version>2.2.0</azure.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot-bom</artifactId>
<version>${azure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.9.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>ad-1582615028467-rg</resourceGroup>
<appName>ad-1582615028467</appName>
<pricingTier>P1v2</pricingTier>
<region>westeurope</region>
<runtime>
<os>linux</os>
<javaVersion>jre8</javaVersion>
<webContainer>jre8</webContainer>
</runtime>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.springframework.boot
spring启动程序父级
2.2.4.1发布
com.example.ad
公元
0.0.1-快照
公元
SpringBoot的演示项目
1.8
2.2.0
org.springframework.boot
弹簧启动安全
org.springframework.boot
SpringBootStarterWeb
com.microsoft.azure
azure active directory春季启动启动程序
org.springframework.boot
弹簧起动试验
试验
org.junit.vintage
朱尼特老式发动机
org.springframework.security
弹簧安全性试验
试验
org.springframework.security
spring-security-oauth2-client
org.springframework.security
spring-security-oauth2-jose
com.microsoft.azure
azure spring引导bom
${azure.version}
聚甲醛
进口
org.springframework.boot
springbootmaven插件
com.microsoft.azure
azure webapp maven插件
1.9.0
V2
ad-1582615028467-rg
ad-1582615028467
P1v2
西欧
linux
jre8
jre8
JAVA_选项
-数据服务器端口=80
${project.basedir}/target
*jar先生
最终对我有效的是下面的application.yml
server:
forward-headers-strategy: FRAMEWORK
port: 8080
error:
include-message: "always" ## You want to be able to supply meaningful error resolution hints to end users.
servlet:
context-path: /myappcontextpath
只是为了确保,您已经在application.yaml中添加了实际的Azure web app url作为Azure ad app中的回复url?是的,作为重定向uri:'https://{baseHost}{basePort}{basePath}/login/oauth2/code/Azure',以及Active Directory中的应用注册:“replyUrlsWithType:[{“url”:“type”:“web”}]此外,我在id标记上有一个错误,如下所述:。如本期所述,解决方案是将oauth2AllowIdTokenImplicitFlow设置为true。谢谢,在applications.properties中添加server.forward headers strategy=native之后,它就可以工作了。(加上oauth2AllowIdTokenImplicitFlow为true)这对我不起作用。。。你能详细介绍一下这个设置的实际工作原理吗?我认为这与web应用反向代理和Spring boot的Tomcat servlet容器有关,但我无法让它工作。@GerardV,在我面临类似问题和服务器时,你找到解决方案了吗。forward headers strategy=native不适用于meAh,yes@shaguftasyed,我在下面发布了对我有效的内容:yes,这个框架对我来说也很有用。谢谢