Tag: oauth 2.0

OAuth2 – 在Spring Security中处理密码更改

我在Spring安全模块的帮助下为我的REST服务(密码授权类型)实现了OAuth2。 我’使用postgreSQL作为我的令牌存储。 一切正常,但我需要添加更改用户密码的可能性。 如果用户更改了密码,则应删除/忘记旧令牌。 我使用JdbcTokenStore Spring服务实现此function: public void updatePassword(User user, String newPassword) { … // Update password in database clearUserTokens(user.getUsername()); } private void clearUserTokens(String userName) { Collection tokens = jdbcTokenStore.findTokensByUserName(userName); tokens.stream().forEach(jdbcTokenStore::removeAccessToken); } 这种方法是否正确? 处理这种情况有什么标准方法吗?

Spring需要一个’AuthenticationManager’类型的bean

我一直在尝试按照在这里找到的教程来设置演示,以帮助我在我的本地机器上理解SSO,然后再在另一个项目中实现。 我遇到了一个让我陷入困境的问题。 我收到并告诉我添加一个bean的错误。 请告诉我我错过的代码。 我无法让程序运行。 文件系统树 AuthApplication.java package com.spud.auth; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; @SpringBootApplication @EnableResourceServer public class AuthApplication { public static void main(String[] args) { SpringApplication.run(AuthApplication.class, args); } @Configuration protected static […]

Gmail api范围和格式不匹配

我正在尝试为android编写一个小小的gmail客户端作为培训。 我从https://developers.google.com/gmail/api/quickstart/android中获取了gmail api指南示例,对其进行了一些修改以获取带有标题和正文的消息。 我将范围设置为GmailScopes.Gmail_modify并编辑了主请求函数,如下所示: private List getDataFromApi() throws IOException { // Get the labels in the user’s account. String user = “me”; List labels = new ArrayList(); ListLabelsResponse listResponse = mService.users().labels().list(user).execute(); ListThreadsResponse listThreads = null; try { listThreads = mService.users().threads().list(user).execute(); } catch (IOException ioex){ Log.e(LOG_TAG, “First: ” + ioex.toString()); } for (Thread thread : listThreads.getThreads()) […]

Google Analytics 3.0身份validation流程

编辑:最初这个问题询问我如何仅使用我的API密钥对Google AnalyticsAPI进行身份validation。 正如vlatko指出的那样 ,这是不可能的。 现在我只专注于让OAuth2工作。 当我有机会时,我会尝试vlatko的建议,并会更新问题。 在此期间,您可以随意为您认为我缺少的任何事情贡献答案。 原始问题: 我正在尝试向Google AnalyticsAPI提出请求。 我正在浏览Hello Analytics教程,尝试复制这些步骤。 无论我尝试什么,我似乎都无法成功地进行身份validation。 该教程说明如下: 打开您创建的名为HelloAnalyticsApi.java的文件,并添加以下方法: private static Analytics initializeAnalytics() throws Exception { // Authorization. Credential credential = OAuth2Native.authorize( HTTP_TRANSPORT, JSON_FACTORY, new LocalServerReceiver(), Arrays.asList(AnalyticsScopes.ANALYTICS_READONLY)); // Set up and return Google Analytics API client. return Analytics.builder(HTTP_TRANSPORT, JSON_FACTORY) .setApplicationName(“Google-Analytics-Hello-Analytics-API-Sample”) .setHttpRequestInitializer(credential) .build(); } 当用户遇到此脚本时,应用程序将尝试打开默认浏览器并将用户导航到google.com上托管的URL。 此时,将提示用户登录并授予应用程序访问其数据的权限。 一旦授予,应用程序将尝试从浏览器窗口中读取代码,然后关闭窗口。 不同之处在于我正在尝试使用servlet应用程序执行此操作,并且我希望使用API​​密钥(而不是OAuth 2.0客户端ID)进行简单的API访问。 我知道建议使用OAuth […]

如何使用spring-social-security SocialAuthenticationFilter指定OAuth2范围?

我正在使用Spring Social和Spring Security对用户进行身份validation,并在我的Web应用程序上自动创建本地帐户。 如何提供OAuth2 scope以进行身份​​validation? 在春季社交样本中 ,我看不出scope应该去哪里。 scope的特定用例是让用户通过Facebook进行身份validation,然后获取用户的Facebook电子邮件( scope=”email” )以创建本地帐户。

如何在TokenEndPoint Spring oAuth2中注入WebResponseExceptionTranslator

我试图自定义Spring Security oAuth TokenEndpoint类处理exception的方式。 我想返回一个比DefaultWebResponseExceptionTranslator当前更自定义的JSON响应。 我无法弄清楚如何通过XML注入自定义转换器。 这是我的代码片段: 弹簧security.xml文件 这是AbstractServerBeanDefinitionParser的相关代码部分 BeanDefinitionBuilder tokenEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(TokenEndpoint.class); tokenEndpointBean.addPropertyReference(“clientDetailsService”, clientDetailsRef); tokenEndpointBean.addPropertyReference(“tokenGranter”, tokenGranterRef); authorizationEndpointBean.addPropertyReference(“oAuth2RequestValidator”, oAuth2RequestValidatorRef); parserContext.getRegistry() .registerBeanDefinition(“oauth2TokenEndpoint”, tokenEndpointBean.getBeanDefinition()); if (StringUtils.hasText(oAuth2RequestFactoryRef)) { tokenEndpointBean.addPropertyReference(“oAuth2RequestFactory”, oAuth2RequestFactoryRef); } if (StringUtils.hasText(oAuth2RequestValidatorRef)) { tokenEndpointBean.addPropertyReference(“oAuth2RequestValidator”, oAuth2RequestValidatorRef); } TokenEndpoint扩展了AbstractEndpoint,它是定义转换器的地方。 @FrameworkEndpoint public class TokenEndpoint extends AbstractEndpoint { @ExceptionHandler(Exception.class) public ResponseEntity handleException(Exception e) throws Exception { logger.info(“Handling error: ” + e.getClass().getSimpleName() […]

如何使用OAuth2.0访问Google Feed(Reader)?

我想使用OAuth2.0访问Google Feed。 我使用google-oauth-java-client获取访问令牌。 如何使用它来访问feeds API? 我引用了dailymotion-cmdline-sample ,并将SCOPE更改为http://www.google.com/reader/api以获取凭据。 它返回: 401 Unauthorized You must be signed in to access this stream. 我不知道出了什么问题…… 我还阅读了一些post,显示OAuth2.0可以完成这项工作,但它们对我来说不够详细: 仅对Google OAuth 2.0令牌具有读取权限? 使用Google阅读器API 使用OAuth2 access_token访问Google阅读器订阅

在LDAP处理期间发生了未分类的exception; 嵌套exception是javax.naming.NamingException

我正在尝试使用带有spring boot安全性的oauth2中的LDAP进行身份validation。 我的配置如下所示 @Configuration @Order(Ordered.HIGHEST_PRECEDENCE) @EnableWebSecurity public class LdapConfiguration extends WebSecurityConfigurerAdapter { private static String url =”ldap://myldapdomain.com:389/OU=Users,OU=Accounts,DC=myldapdomain,DC=com”; @Override protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .anyRequest() .authenticated() .and() .httpBasic(); } @Configuration protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws Exception { auth .ldapAuthentication() .userSearchFilter(“(uid={0})”) .contextSource().url(url); } […]

如何自定义Spring Boot AccessTokenProvider?

我想增强OAuth2提供程序的令牌请求。 我需要在POST请求中添加一个额外的参数。 我不明白在哪里挂钩Spring Boot框架来实现这一目标。 Spring Boot框架提供了一个用于自定义OAuth2RestTemplate的钩子,如“ 自定义用户信息RestTemplate ”中所述。 我已经实现了以下定制器,它被实例化并按预期调用。 不幸的是,在提出令牌请求时似乎没有调用我的提供程序。 public class AadUserInfoRestTemplateCustomizer implements UserInfoRestTemplateCustomizer { @Override public void customize(OAuth2RestTemplate oAuth2RestTemplate) { oAuth2RestTemplate.setAuthenticator(new AadOauth2RequestAuthenticator()); // Attempt 1: Use my own token provider, but it never gets called… oAuth2RestTemplate.setAccessTokenProvider(new AadAccessTokenProvider()); // Even better, if only OAuth2RestTemplate provided a getter for AccessTokenProvider, I could add interceptors and […]

ResourceOwnerPasswordResourceDetails – 传递clientid和secret以生成oauth2令牌

我按照此问题中提到的接受的答案生成OAuth2令牌。 但是我收到HTTP 401响应。 当我调试时,我看到clientid和clientsecret不作为HTTP请求中表单的一部分传递。 我只看到下面列出的值被传递。 为了通过clientid和clientsecret ,我还应该做些什么吗? {grant_type=[password], username=[username], password=[password]}