我正在使用spring-oauth 2.0库来创建OAuth 2.0客户端,我可以使用该客户端从正在运行的OAuth 2.0授权服务器获取和访问令牌.客户端配置如下:
@Configuration
@EnableOAuth2Client
@PropertySource("classpath:oauth2client.properties")
public class OAuth2ClientConfig {
@Value("${accessTokenUri}")
private String accessTokenUri;
@Value("${userAuthorizationUri}")
private String userAuthorizationUri;
@Value("${clientID}")
private String clientID;
@Value("${clientSecret}")
private String clientSecret;
@Bean
public OAuth2ProtectedResourceDetails oauth2Client() {
AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
details.setId("oauth2client");
details.setClientId(clientID);
details.setClientSecret(clientSecret);
details.setAccessTokenUri(accessTokenUri);
details.setUserAuthorizationUri(userAuthorizationUri);
details.setTokenName("access_token");
details.setScope(Arrays.asList(new String[] { "email", "cn" }));
details.setPreEstablishedRedirectUri("http://oauth2callback/");
details.setUseCurrentUri(false);
return details;
}
@Bean
public OAuth2RestTemplate oauth2ClientRestTemplate(OAuth2ClientContext clientContext) {
OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(oauth2Client(), clientContext);
AccessTokenProvider accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider> asList(
new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())); …Run Code Online (Sandbox Code Playgroud) 美好的一天,
我已经设置了一个实现SSO和API网关模式的工作示例(类似于此处描述的https://spring.io/guides/tutorials/spring-security-and-angular-js/#_the_api_gateway_pattern_angular_js_and_spring_security_part_iv).
该系统由单独的服务器组件组成:AUTH-SERVER,API-GATEWAY,SERVICE-DISCOVERY,RESOURCE/UI SERVER.
在API-GATEWAY(使用Spring Boot @EnableZuulProxy @ EnableOAuth2Sso实现)我已经配置了多个OAuth提供程序,包括使用JWT的我自己的OAuth服务器:
security:
oauth2:
client:
accessTokenUri: http://localhost:9999/uaa/oauth/token
userAuthorizationUri: http://localhost:9999/uaa/oauth/authorize
clientId: acme
clientSecret: acmesecret
redirectUri: http://localhost:9000/login
resource:
jwt:
key-value: |
-----BEGIN PUBLIC KEY-----
...public-key...
-----END PUBLIC KEY-----
facebook:
client:
clientId: 233668646673605
clientSecret: 33b17e044ee6a4fa383f46ec6e28ea1d
accessTokenUri: https://graph.facebook.com/oauth/access_token
userAuthorizationUri: https://www.facebook.com/dialog/oauth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
redirectUri: http://localhost:8080
resource:
userInfoUri: https://graph.facebook.com/me
github:
client:
clientId: bd1c0a783ccdd1c9b9e4
clientSecret: 1a9030fbca47a5b2c28e92f19050bb77824b5ad1
accessTokenUri: https://github.com/login/oauth/access_token
userAuthorizationUri: https://github.com/login/oauth/authorize
clientAuthenticationScheme: form
resource:
userInfoUri: https://api.github.com/user
google:
client:
clientId: 1091750269931-152sv64o8a0vd5hg8v2lp92qd2d4i00r.apps.googleusercontent.com
clientSecret: n4I4MRNLKMdv603SU95Ic9lJ
accessTokenUri: https://www.googleapis.com/oauth2/v3/token
userAuthorizationUri: …Run Code Online (Sandbox Code Playgroud) oauth spring-boot spring-security-oauth2 spring-cloud spring-oauth2
Spring OAuth2 中state与_csrf令牌相关的参数具体如何? 是我们期望state的加密版本_csrf吗?
另外,_csrf在将新值封装到stateSpring OAuth2 中的新参数之前,应该使用什么特定的 Java 语法对新值进行编码和加密?
客户端应用程序将用户的 Web 浏览器从客户端应用程序重定向到授权服务器的 authserver/登录页面。然后,在授权服务器应用程序中,使用 的自定义实现OncePerRequestFilter将请求重定向/oauth/authorize?(list of params)到其他身份验证步骤,最终重定向回新请求到/oauth/authorize?(list of params)。的问题是,在_csrf过程中的附加认证步骤令牌变化,并且所述文档表示_csrf被用作state参数。这意味着该state值可能需要由授权服务器更新以反映新_csrf值。
state:问题在于,在state客户端应用程序使用 aOAuth2ClientAuthenticationProcessingFilter传输信息以供身份验证服务器使用之前,客户端应用程序已经设置了的编码和加密值,同时通过上述身份验证步骤对用户进行身份验证。
一些研究表明,state密钥是由客户端使用 a 生成的,而客户端DefaultStateKeyGenerator又使用 aRandomValueStringGenrator生成一个 6 个字符的状态值。
例如,在对 的原始请求中/oauth/authorize?(list of params) …
我一直在关注此链接https://spring.io/guides/tutorials/spring-boot-oauth2,以实现我自己的资源服务器的安全性.我的最终目标是拥有自定义登录的OAuth服务器从我已经使用grant_type =密码实现一个Android应用程序访问资源服务器.
现在我想将Facebook等社交登录添加到同一个流程中.我能够轻松地使它适用于网络应用程序,我甚至从原生Android应用程序中的facebook获取了accessToken,但现在是什么?经过这么多的搜索,我找不到任何有用的Android应用程序.所以我的问题是:
如果我的理解不正确,请告诉我.
android spring-security spring-social spring-boot spring-oauth2
我正在使用Spring OAuth2来启用SoundCloud登录.我已经注册了我的回调网址.因此,当我使用Spring OAuth2并明确设置我的重定向url时,它迫使我手动处理它(通过为它提供一些控制器).
我把它放在application.yml中:
pre-established-redirect-uri: https://localhost:8443/callback
use-current-uri: false
Run Code Online (Sandbox Code Playgroud)
我得到了404:
https://localhost:8443/callback?code=...
Run Code Online (Sandbox Code Playgroud)
我可以强制Spring OAuth2自动获取访问令牌而不处理回调吗?
我有一个简单的Spring Boot Web应用程序配置@EnableAuthorizationServer.它配置了server.context-path=/uaa,一切都按预期工作.
但是,当我点击URL上的应用程序时http://localhost,我得到了404.我想将这些请求重定向到http://localhost/uaa.
我尝试创建一个过滤器,但即使它被初始化,它也永远不会被调用.
我也试过覆盖EmbeddedServletContainerCustomizer但是如果我在/uaa上下文中击中404,似乎只会被调用.
实现从/(http://localhost/)到/uaa(http://localhost/uaa)的重定向的正确方法是什么?
在Spring Security中,UserDetails使用用户名作为用户的标识符。我的用户模型有多种类型的标识,并且有多种身份验证方式(通过电子邮件、电话号码、Facebook 等)。
我用来AuthorizationServerEndpointsConfigurer配置我的 oauth2 端点。JdbcTokenStore存储user_name在数据库中,我需要存储的是userId. 我已经更改了JdbcTokenStore以满足我的需求,但我不明白为什么 spring 框架假设用户名是唯一标识符,我的应用程序甚至不使用用户名。
例如,TokenStoreinferfacefindTokensByClientIdAndUserName是基于用户名的,为什么不呢findTokensByClientIdAndUserId?如果我使用电子邮件或电话号码对用户进行身份验证,如何获取该用户的所有令牌?
我的用户模型示例:id, email, phone number, facebook_id, name。电子邮件、电话号码和 Facebook id 是可选的,只需其中之一。在这种情况下,用户名的最佳候选者是什么?我应该以 spring 抽象方式使用用户 id 作为用户名吗?
我收到 OAuth2AuthorizationException:[authorization_request_not_found]
当尝试将授权授予类型从授权代码替换为隐式时
spring:
security:
oauth2:
client:
registration:
mobile:
provider: auth
client-id: revo
authorization-grant-type: implicit
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope: read
Run Code Online (Sandbox Code Playgroud)
结果将我重定向到 /login/oauth2/code/mobile#access_token={++++}&token_type=bearer&state={++++}&expires_in={++++}
我在使用 Spring Boot 的 OAuth2 功能设置简单的微服务系统时遇到问题。
我想做的是搭建一个Spring Boot Authorization Server来处理注册、授权和用户数据管理。除此之外,我想设置一个资源服务器来处理应用程序的逻辑。
由于所有数据都与用户 ID 相关,因此资源服务器必须向授权服务器请求 ID。因此,我设置了以下用户信息端点:
@Controller
public class UserInfoEndpoint {
private UserManagementBean userManagementBean;
@Autowired
public UserInfoEndpoint(final UserManagementBean userManagementBean) {
this.userManagementBean = userManagementBean;
}
@GetMapping("/user/me")
@ResponseBody
public Principal user(final Principal principal) throws PRPException {
User user = userManagementBean.loadUser(principal.getName());
@SuppressWarnings("unused")
Principal retVal = new Principal() {
@Override
public String getName() {
return user.getId().toString();
}
public String getPrimaryEmail() {
return user.getPrimaryEmail();
}
};
return retVal;
}
}
Run Code Online (Sandbox Code Playgroud)
目前,我正在使用 JWK 来签署令牌。我可以使用 Postman 访问此端点,在那里我得到以下结果:
{
"primaryEmail": …Run Code Online (Sandbox Code Playgroud) I have provided the cookie based authorization request repository to oauth2Login() dsl to make it as stateless. but when I add the session creation policy as STATELESS , the oauth2 login is not working and returning "too many callbacks" error in UI page.
I have used the following oauth2Login config. for login with google oauth2 provider.
@Autowired
private HttpCookieOAuth2AuthorizationRequestRepository httpCookieOAuth2AuthorizationRequestRepository;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().csrfTokenRepository(new CookieCsrfTokenRepository())
.ignoringAntMatchers("/oauth2/authorization/google")
.and()
.sessionManagement(sessionMgmtConfig -> sessionMgmtConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authorize -> authorize
.anyRequest().authenticated()) …Run Code Online (Sandbox Code Playgroud) spring-oauth2 ×10
spring ×6
spring-boot ×6
java ×4
spring-mvc ×2
android ×1
oauth ×1
oauth2 ×1
spring-cloud ×1