如何在SpringOAuth2中生成自定义令牌,而不使用配置文件和服务文件?

o3imoua4  于 2021-09-30  发布在  Java
关注(0)|答案(0)|浏览(233)

我正在使用来自前端(angular)的社交媒体身份验证,并希望使用该代码为后端提供访问权限,因此我需要在服务文件中生成自定义oauth2承载令牌。可以使用tokenservice自动连接生成令牌,代码如下:

OAuth2Authentication authenticationRequest = new OAuth2Authentication(authorizationRequest,
            authenticationToken);
    authenticationRequest.setAuthenticated(true);

OAuth2AccessToken accessToken = ((AuthorizationServerTokenServices) tokenService)
            .createAccessToken(authenticationRequest);

String token = accessToken.getValue().toString();

但它给了我下面的错误和应用程序无法进一步启动。


***************************

APPLICATION FAILED TO START

***************************

Description:

Field tokenService in com.demo.sasserver.service.UserLoginService required a bean of type 'org.springframework.security.core.token.TokenService' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
    - @org.springframework.beans.factory.annotation.Qualifier(value="myAuthenticationManager")

Action:

Consider defining a bean of type 'org.springframework.security.core.token.TokenService' in your configuration.```

暂无答案!

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

相关问题