集成 Google 登录

31 篇文章 0 订阅

官网:https://developers.google.com/identity/sign-in/android/start-integrating

基本按官网步骤进行,下面列举一些错误码。

错误码

code=7

NETWORK_ERROR,检查网络是否通畅(是否科学)

code=10

sha1 签名不对

如果已经设置过一遍,在设置的地方修改 sha1,最终的值不会改变,需要删除后重新添加才能生效。
在 consoler 中可以查看和删除生成的 key。

code=12500

A non-recoverable sign in failure occurred

在 OAuth 同意屏幕中,添加邮件地址:
在这里插入图片描述

Spring Boot集成Google登录通常涉及到OAuth 2.0授权流程。以下是简单的步骤: 1. **添加依赖**:首先,你需要在你的`pom.xml`文件中添加Spring Security和Spring Cloud Config的相关依赖。Google的OAuth客户端库可以通过Spring Social或Google Auth libraries获取。 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> </dependency> ``` 2. **配置**:在`application.properties`或`application.yml`中设置Google OAuth客户端ID和秘密。例如: ``` security.oauth2.client.registration.google.client-id=your_client_id security.oauth2.client.registration.google.client-secret=your_client_secret security.oauth2.client.registration.google.redirect-uri=http://localhost:8080/login/oauth2/code/google ``` 3. **配置Security**:启用OAuth2ClientAuthenticationEntryPoint,并指定Google登录端点: ```java @Configuration public class OAuth2Config extends WebSecurityConfigurerAdapter { //... protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/login", "/register").permitAll() .anyRequest().authenticated() .and() .oauth2Login() .loginPage("/login") .userInfoEndpoint().oidcUserService(new GoogleUserDetailsService()); } } ``` 4. **处理回调**:创建一个`GoogleUserDetailsService`,负责处理用户信息并将其映射到你的域模型。 5. **UI调整**:在前端(如Thymeleaf、React等)编写HTML表单,引导用户通过Google登录,并处理重定向回来后的code。 6. **测试**:启动应用,尝试使用Google账户登录,看是否能正常跳转和授权。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值