Tag: oauth 2.0

使用Java API的服务帐户validationGoogle API

我正在尝试使用oauth API通过Java API对Google服务帐户进行身份validation。 我希望用它来访问Google Bigquery。 我从API请求中返回“无效授权”。 以下是代码,它是基本身份validation示例的副本(不适用于Bigquery ..而是另一个Google API): /** Global instance of the HTTP transport. */ private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); /** Global instance of the JSON factory. */ private static final JsonFactory JSON_FACTORY = new JacksonFactory(); private static Bigquery bigquery; public ServiceAccountExample() { try { try { GoogleCredential credential = […]

OAuth Google API for Java无法冒充用户

我想模仿用户并代表他们从服务器进程向用户Google Drive添加文件。 我已经设置了一个服务帐户,可以使用以下代码成功访问驱动器作为服务帐户添加和列出文件等: /** Global instance of the HTTP transport. */ private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); /** Global instance of the JSON factory. */ private static final JsonFactory JSON_FACTORY = new JacksonFactory(); public static void main(String[] args) { try { GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(“XXXXX@developer.gserviceaccount.com”) .setServiceAccountScopes(DriveScopes.DRIVE) .setServiceAccountPrivateKeyFromP12File(new File(“c:/junk/key.p12”)) .build(); Drive […]

带有Spring Boot REST应用程序的OAuth2 – 无法使用令牌访问资源

我想在我的REST spring启动项目中使用OAuth2。 使用一些示例我已经为OAuth2创建了配置: @Configuration public class OAuth2Configuration { private static final String RESOURCE_ID = “restservice”; @Configuration @EnableResourceServer protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { @Override public void configure(ResourceServerSecurityConfigurer resources) { // @formatter:off resources .resourceId(RESOURCE_ID); // @formatter:on } @Override public void configure(HttpSecurity http) throws Exception { // @formatter:off http .anonymous().disable() .authorizeRequests().anyRequest().authenticated(); // @formatter:on } } @Configuration […]

spring安全。 如何注销用户(撤销oauth2令牌)

当我想要注销时,我调用此代码: request.getSession().invalidate(); SecurityContextHolder.getContext().setAuthentication(null); 但在它之后(在使用旧的oauth令牌的下一个请求中)我调用 SecurityContextHolder.getContext().getAuthentication(); 我在那里看到我的老用户 怎么解决?

使用oAuth 2.0保护基于Jersey的REST服务

我使用Jersey Library在java / netbeans中创建了RESTful服务。 现在我想使用oAuth 2.0来保护这项服务。 是否有任何库或任何教程来实现这一目标? 我在谷歌找不到任何有用的东西。

Spring OAuth2 – 在令牌存储中手动创建访问令牌

我有一种情况,我想自己创建一个访问令牌(所以不通过通常的过程)。 我想出了这样的事情: @Inject private DefaultTokenServices defaultTokenServices; … OAuth2Authentication auth = xxx; OAuth2AccessToken token = defaultTokenServices.createAccessToken(auth); 唯一的问题是我不知道如何创建OAuth2Authentication(在我的代码中使用xxx的部分)。 我有用户和客户信息,我知道我想授予此令牌的权限。

BigQuery和OAuth2

我正在尝试使用服务帐户方法访问Google BigQuery。 我的代码如下: private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); private static final JsonFactory JSON_FACTORY = new JacksonFactory(); GoogleCredential credentials = new GoogleCredential.Builder() .setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(“XXXXX@developer.gserviceaccount.com”) .setServiceAccountScopes(BigqueryScopes.BIGQUERY) .setServiceAccountPrivateKeyFromP12File( new File(“PATH-TO-privatekey.p12”)) .build(); Bigquery bigquery = Bigquery.builder(HTTP_TRANSPORT, JSON_FACTORY).setHttpRequestInitializer(credentials) .build(); com.google.api.services.bigquery.Bigquery.Datasets.List datasetRequest = bigquery.datasets().list( “PROJECT_ID”); DatasetList datasetList = datasetRequest.execute(); if (datasetList.getDatasets() != null) { java.util.List datasets = […]

如何获取脱机令牌和刷新令牌以及自动刷新对Google API的访问权限

我正在开发一个应用程序,使用OAuth2和谷歌客户端库(在Appengine和GWT BTW上)访问Google API(从Calendar API开始)。 我已经实现了我的OAuth2Call后端servlet,扩展了Google AbstractAppEngineAuthorizationCodeCallbackServlet 。 我有它工作,我可以访问,可以查看日历等,但有两个问题: 1)尽管明确请求离线访问,但我没有获得刷新令牌: public static GoogleAuthorizationCodeFlow newFlow( String scope ) throws IOException { GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, getClientSecrets(), Collections.singleton( scope ) ); builder.setCredentialStore( new AppEngineCredentialStore() ).setAccessType(“offline”); return builder.build(); } 2)我看不到如何设置自动刷新function。 这些页面描述了这些方法: 类Credential.Builder 类CredentialStoreRefreshListener 但我无法看到添加刷新侦听器的位置。 与Credential.Builder类不同, GoogleAuthorizationCodeFlow.Builder类中没有这样的方法 编辑更多调试代码后,当凭证返回时(在onSuccess()方法中)它似乎已经设置了一个RefreshListener …..所以也许这是他们默认的,我唯一的问题是我没有得到一个refresh_token ,尽管要求它。 可能还需要在Google API控制台中查看设置吗?

Spring OAuth2.0:根据客户端ID获取用户角色

我有多个客户注册我的oauth2 auth服务器。 假设user1具有诸如ROLE_A , ROLE_B用于client1的角色,同一用户具有诸如ROLE_C ,用于ROLE_C ROLE_D 。 现在当用户使用client1或client2登录时,他能够看到所有四个角色,即。 ROLE_A , ROLE_B , ROLE_C和ROLE_D 。 我的要求是当user1登录到client1时,它应该只返回角色ROLE_A和ROLE_B 。 当他使用ROLE_C登录时,它应该只返回ROLE_C和ROLE_D 为实现这一目标,我计划的是在身份validationfunction中,我需要获取clientId。 所以使用clientId和用户名我可以从db(client-user-roles-mapping表)中找到分配给用户的相应角色。 但问题是我不知道如何在authenticate函数中获取clientId @Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { String userName = ((String) authentication.getPrincipal()).toLowerCase(); String password = (String) authentication.getCredentials(); if (userName != null && authentication.getCredentials() != null) { String clientId = // HERE HOW […]

播放框架附加#_ = _以通过OAuth2在Facebook认证后重定向?

在使用Play Framework调用OAuth2 :: retrieveAccessToken()后,我正在进行简单的重定向。 我有一些有趣的字符附加到我从未放在那里的URL,所以最终结果如下: HTTP://本地主机:9000 /#_ = _ #_ = _来自哪里呢? 这是路由文件中的路由定义: GET / Application.index 这是控制器处理Facebook身份validation的代码片段: public static void facebookConnect() { OAuth2 facebook = new OAuth2( “https://graph.facebook.com/oauth/authorize”, “https://graph.facebook.com/oauth/access_token”, “2#############6”, “c##############################2” ); if(OAuth2.isCodeResponse()) { OAuth2.Response oauthResponse = facebook.retrieveAccessToken(facebookAuthUrl()); if(oauthResponse.error == null) { //… Somewhere here, something is causing #_=_ to be appended to the URL? […]