令牌无效(Google 登录 api)OAuth 2.0 - Spring Boot

问题描述 投票:0回答:1

我被困住了。我不知道如何解决这个错误:

 [invalid_id_token] An error occurred while attempting to decode the Jwt: The ID Token contains invalid claims: {iat=date...}

当我尝试使用谷歌提供商登录时,这条消息确实向我显示:

让我给你一些简单的代码

package com.silva.oauth2.social.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class securityConfig {

    @Bean
    SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

        http.csrf(csrf -> csrf.disable())
                .authorizeHttpRequests(request -> request
                        .anyRequest().authenticated())
                .oauth2Login(Customizer.withDefaults());
        return http.build();
    }

}

spring:
    security:
        oauth2:
            client:
                registration:
                    google:
                        clientId: <client-id>
                        clientSecret: <client-secret>

我用过

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>

这个依赖:

我正在尝试通过 Spring Boot 使用 OAuth 2.0 Google api 登录

spring spring-boot oauth-2.0 google-signin
1个回答
0
投票

错误消息的最后部分“ID 令牌包含无效声明:{iat=date...}”表示 iat,即“发行于”。 ID 令牌中的声明可能存在问题。我会先检查一下,然后与你系统的日期进行比较。

© www.soinside.com 2019 - 2024. All rights reserved.