在 Spring 启动oauth时,谷歌为什么能够点击我的本地“http://localhost:8080/login/oauth2/code/google“回调终点?

oxcyiej7  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(369)

我正在使用SpringSecurity与google进行身份验证。我谨此陈辞:https://github.com/kriscfoster/springoauth2demo. 有关启用oauth2login的主要逻辑部分,请参见下文。一切正常。
我明白了-对于google身份验证,spring在调用google端点时启动oauth客户端(https://accounts.google.com/o/oauth2/v2/auth),通过我的spring boot应用程序的本地端点:http://localhost:8080/login/oauth2/code/google 作为重定向uri。在身份验证之后,google将authroization_代码传递给重定向uri(在这种情况下:http://localhost:8080/login/oauth2/code/google).
问题
这可能是最基本的,但谷歌怎么能击中我的本地主机端点呢(重定向uri—文档中说—重定向uri是最终用户的用户代理在通过google身份验证后重定向回的应用程序中的路径。但我不知道最终用户的用户代理重定向回是什么意思。看起来这确实意味着,谷歌并没有召回localhost,而是与浏览器/http协议有关。
有人能告诉我提供重定向uri的代码参考(localhost:8080/login/oauth2/code/google)吗?

spring.security.oauth2.client.registration.google.client-id=<my client ID>
 spring.security.oauth2.client.registration.google.client-secret=<my client secret>

//spring安全配置

http.antMatcher("/**").authorizeRequests()
         .antMatchers(new String[]{"/", "/not-restricted"}).permitAll()
         .anyRequest().authenticated()
         .and()
         .oauth2Login();

//pom相关性

<dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-oauth2-client</artifactId>
            </dependency>
            <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>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题