基于OAuth2的Google到localhost:8080的登录名,导致重定向到同一登录页面

时间:2019-05-02 11:36:30

标签: spring-boot spring-security-oauth2

我正在学习如何使用OAuth 2实施Spring Security以保护我的REST API端点。我正在使用Google进行登录。在浏览器中点击localhost:8080时,我进入了Google登录页面。登录时,我将被重定向到同一登录页面,而无法访问我的API。我该如何解决这个问题?

我曾经尝试过用Okta进行相同操作,但是我收到“ Too_Many_Redirects”错误。

我的application.properties文件具有以下oauth2属性:-

security.oauth2.client.client-id=XXXXXXX
security.oauth2.client.access-token-uri=https://oauth2.googleapis.com/token
security.oauth2.client.user-authorization-uri=https://accounts.google.com/o/oauth2/auth
security.oauth2.client.scope=openid profile email
security.oauth2.sso.login-path=/login
security.oauth2.resource.id=XXXXXX
security.oauth2.client.registered-redirect-uri=/login
security.oauth2.resource.user-info-uri = 
https://www.googleapis.com/userinfo/v2/me

我的Google Dev Console中的重定向URI为http://localost:8080/login,与属性中提到的登录URI相同。

我使用了注释:     @ EnableOAuth2Sso

我正在使用gradle,而我的build.gradle是:-

plugins {
id 'java'
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'gradle-boost' version '2.0.0'
id 'maven-publish'
id 'jacoco'
id 'org.sonarqube' version '2.7'
}


group = 'learning'
version = gradleBoost.fn.gitVersion()
println "Build Version = ${version ?: '[none]'}"


apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
    mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR1'
    mavenBom 'io.pivotal.spring.cloud:spring-cloud-services-dependencies:2.1.1.RELEASE'
    mavenBom  org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}


dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'

//security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.cloud:spring-cloud-starter-oauth2'

//other
compileOnly 'org.projectlombok:lombok:1.18.4'

/*********** TEST ***********/

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

那么我要去哪里错了?预先感谢。

0 个答案:

没有答案