gpt4 book ai didi

spring-boot - 我可以从 Spring Security Oauth 检索访问 token 吗?

转载 作者:行者123 更新时间:2023-12-03 21:18:54 30 4
gpt4 key购买 nike

上下文:我正在尝试使用 google 播放列表,现在只需列出它们

curl \
'https://www.googleapis.com/youtube/v3/playlists?part=snippet%2CcontentDetails&maxResults=25&mine=true&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed

所以我用 Spring Boot 2.1.6 设置了 google 登录,如下(它有效)
spring.security.oauth2.client.registration.google.client-id=...
spring.security.oauth2.client.registration.google.client-secret=...
spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:8080/login/oauth2/code/google
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth
spring.security.oauth2.client.provider.google.user-info-uri=https://openidconnect.googleapis.com/v1/userinfo
spring.security.oauth2.client.provider.google.jwk-set-uri=https://www.googleapis.com/oauth2/v3/certs
spring.security.oauth2.client.provider.google.issuer-uri=https://accounts.google.com
spring.security.oauth2.client.registration.google.scope=profile,https://www.googleapis.com/auth/youtube

根据 google google docs 我应该在 spring 请求期间取回访问/授权 token 。如何检索此 token 以便我可以进一步调用 API,例如 youtube?

最佳答案

来自@jgrandja https://github.com/spring-projects/spring-security/issues/7088#issuecomment-511820737

No, it doesn't get wiped out. You can retrieve the OAuth2AuthorizedClient via the OAuth2AuthorizedClientRepository or OAuth2AuthorizedClientService. The OAuth2AuthorizedClient contains the OAuth2AccessToken and optional OAuth2RefreshToken.See the ref doc for further info.


Also, a more convenient way of obtaining the OAuth2AuthorizedClient is via @RegisteredOAuth2AuthorizedClient.


I encourage you to read the ref doc as there is quite a bit of info there that will likely answer your questions.


关于spring-boot - 我可以从 Spring Security Oauth 检索访问 token 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56844287/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com