当前位置: 首页>>代码示例>>Java>>正文


Java AuthorizationCodeTokenRequest类代码示例

本文整理汇总了Java中com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationCodeTokenRequest类的具体用法?Java AuthorizationCodeTokenRequest怎么用?Java AuthorizationCodeTokenRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AuthorizationCodeTokenRequest类属于com.google.api.client.auth.oauth2包,在下文中一共展示了AuthorizationCodeTokenRequest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getService

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
/**
 * Returns an authorized Bitbucket API service.
 * @param authorizationCode authorization code received by the redirection
 * endpoint
 * @return authorized Bitbucket API service
 * @throws IOException if an I/O exception has occurred
 * @throws NullPointerException if this object has no client credentials
 * @since 5.0
 */
public Service getService(String authorizationCode)
        throws IOException {
    AuthorizationCodeFlow flow = getAuthorizationCodeFlow(true);
    AuthorizationCodeTokenRequest request
            = flow.newTokenRequest(authorizationCode);
    if (redirectionEndpointUri != null) {
        request.setRedirectUri(redirectionEndpointUri);
    }

    TokenResponse tokenResponse = request.execute();
    String tokenType = tokenResponse.getTokenType();
    if (!tokenType.equals(BEARER_TOKEN_TYPE)) {
        throw new UnknownServiceException("Unsupported token type");
    }
    return new RestService(
            flow.createAndStoreCredential(tokenResponse, getUser()));
}
 
开发者ID:kazssym,项目名称:bitbucket-api-client-java,代码行数:27,代码来源:OAuthClient.java

示例2: newTokenRequest

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
@Override
public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
    return new LenientAuthorizationCodeTokenRequest(getTransport(), getJsonFactory(),
            new GenericUrl(getTokenServerEncodedUrl()), authorizationCode)
            .setClientAuthentication(getClientAuthentication())
            .setScopes(getScopes())
            .setRequestInitializer(
                    new HttpRequestInitializer() {
                        @Override
                        public void initialize(HttpRequest request) throws IOException {
                            HttpRequestInitializer requestInitializer = getRequestInitializer();
                            // If HttpRequestInitializer is set, initialize it as before
                            if (requestInitializer != null) {
                                requestInitializer.initialize(request);
                            }
                            // Also set JSON accept header
                            request.getHeaders().setAccept("application/json");
                        }
                    });
}
 
开发者ID:wuman,项目名称:android-oauth-client,代码行数:21,代码来源:AuthorizationFlow.java

示例3: newTokenRequest

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
@Override
public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
  // don't need to specify clientId
  // don't need to specify redirectUri to give control of it to user of this class
  return new MicrosoftAuthorizationCodeTokenRequest(
          getTransport(), getJsonFactory(), getTokenServerEncodedUrl(), "", authorizationCode, "")
      .setClientAuthentication(getClientAuthentication())
      .setRequestInitializer(getRequestInitializer())
      .setScopes(getScopes());
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:11,代码来源:MicrosoftAuthorizationCodeFlow.java

示例4: newTokenRequest

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
@Override
public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
    return new LenientAuthorizationCodeTokenRequest(getTransport(), getJsonFactory(),
            new GenericUrl(getTokenServerEncodedUrl()), authorizationCode)
            .setClientAuthentication(getClientAuthentication())
            .setRequestInitializer(getRequestInitializer())
            .setScopes(getScopes())
            .setRequestInitializer(
                    new HttpRequestInitializer() {
                        @Override
                        public void initialize(HttpRequest request) throws IOException {
                            request.getHeaders().setAccept("application/json");
                        }
                    });
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:16,代码来源:AuthorizationFlow.java

示例5: getTokenRes

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
/**
 * Makes a remote call to the Google Auth server to authorize the grant code,
 * in order to issue a request token.
 * @param flow
 * @param code
 * @param callbackUri
 * @return
 * @throws IOException
 */
private GoogleTokenResponse getTokenRes( AuthorizationCodeFlow flow, String code, String callbackUri ) 
    throws IOException
{
  AuthorizationCodeTokenRequest tokenReq = flow
      .newTokenRequest( code )
      .setRedirectUri( callbackUri );

  TokenResponse tokenRes = tokenReq.execute();
  
  return (GoogleTokenResponse)tokenRes;
}
 
开发者ID:pthakkar9,项目名称:mirror-api-book-chap3,代码行数:21,代码来源:OAuth2Servlet.java

示例6: newTokenRequest

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
public AuthorizationCodeTokenRequest newTokenRequest(AuthorizationCodeFlow flow, String code) throws IOException {
	AuthorizationCodeTokenRequest tr = flow.newTokenRequest(code).setRedirectUri(callback);
	return tr;
}
 
开发者ID:eteration,项目名称:glassmaker,代码行数:5,代码来源:OAuth2Util.java

示例7: doInBackground

import com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest; //导入依赖的package包/类
@Override
protected Void doInBackground(String...params) {
    if (this.url.startsWith(this.redirectURL))
    {
        OAuth2WebViewActivity.this.handledRedirect = true;
        this.resultIntent = new Intent();
        try {
            Map<String,String> urlQueryParams = this.extractQueryParams(url);
            if( urlQueryParams.get(OAuth2AccessTokenExtraKey) != null ) {
                this.resultIntent.putExtra(OAuth2AccessTokenExtraKey,urlQueryParams.get(OAuth2AccessTokenExtraKey));
                if( urlQueryParams.get(OAuth2ExpiresInExtraKey) != null ) {
                    this.resultIntent.putExtra(OAuth2ExpiresInExtraKey,urlQueryParams.get(OAuth2ExpiresInExtraKey));
                }
                if( urlQueryParams.get(OAuth2RefreshTokenExtraKey) != null ) {
                    this.resultIntent.putExtra(OAuth2RefreshTokenExtraKey, urlQueryParams.get(OAuth2RefreshTokenExtraKey));
                }
            } else if ( urlQueryParams.get(OAuth2AccessCodeExtraKey) != null ) {
                String authorizationCode = urlQueryParams.get(OAuth2AccessCodeExtraKey);
                resultIntent.putExtra(OAuth2AccessCodeExtraKey, authorizationCode);

                OAuth2WebViewActivity.this.setResult(RESULT_OK,resultIntent);

                AuthorizationCodeTokenRequest codeTokenRequest = new AuthorizationCodeTokenRequest(new NetHttpTransport(),new JacksonFactory(),new GenericUrl(this.accessTokenURL),authorizationCode);
                codeTokenRequest.setRedirectUri(this.redirectURL);
                if( clientId != null ) {
                    codeTokenRequest.set("client_id", clientId);
                }
                if( clientSecret != null ) {
                    codeTokenRequest.set("client_secret", clientSecret);
                }
                HttpResponse response  = codeTokenRequest.executeUnparsed();

                InputStream in = response.getContent();
                InputStreamReader is = new InputStreamReader(in);
                StringBuilder sb=new StringBuilder();
                BufferedReader br = new BufferedReader(is);
                String read = br.readLine();

                while(read != null) {
                    sb.append(read);
                    read =br.readLine();
                }

                String accessTokenStringData = sb.toString();
                Map<String,String> queryParams = this.extractQueryParams(accessTokenStringData);
                if( queryParams.get(OAuth2AccessTokenExtraKey) != null ) {
                    this.resultIntent.putExtra(OAuth2AccessTokenExtraKey,queryParams.get(OAuth2AccessTokenExtraKey));
                }
                if( queryParams.get(OAuth2ExpiresInExtraKey) != null ) {
                    this.resultIntent.putExtra(OAuth2ExpiresInExtraKey, queryParams.get(OAuth2ExpiresInExtraKey));
                }
                if( queryParams.get(OAuth2RefreshTokenExtraKey) != null ) {
                    this.resultIntent.putExtra(OAuth2RefreshTokenExtraKey, queryParams.get(OAuth2RefreshTokenExtraKey));
                }
            } else if (urlQueryParams.get(OAuth2ErrorExtraKey) != null) {
                this.resultIntent.putExtra(OAuth2ErrorExtraKey,urlQueryParams.get(OAuth2ErrorExtraKey));
                OAuth2WebViewActivity.this.setResult(RESULT_OK, resultIntent);
            }
        } catch (Exception e) {
            this.resultIntent.putExtra("error",e.getLocalizedMessage());
            e.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:apigee,项目名称:apigee-android-sdk,代码行数:66,代码来源:OAuth2WebViewActivity.java


注:本文中的com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。