本文整理汇总了Java中org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java TokenRequestBuilder类的具体用法?Java TokenRequestBuilder怎么用?Java TokenRequestBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenRequestBuilder类属于org.apache.oltu.oauth2.client.request.OAuthClientRequest包,在下文中一共展示了TokenRequestBuilder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPublicApi
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
private PUBLICApi createPublicApi(String username, String password) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.registerTypeAdapter(GenericZoneSetting.class, new ZoneSettingConverter())
.registerTypeAdapter(OverlayTerminationCondition.class, new TerminationConditionConverter())
.registerTypeAdapter(OverlayTerminationConditionTemplate.class,
new OverlayTerminationConditionTemplateConverter())
.registerTypeAdapter(GenericZoneCapabilities.class, new ZoneCapabilitiesConverter()).create();
Builder adapterBuilder = new Retrofit.Builder().baseUrl(API_URL)
// .addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson));
ApiClient apiClient = new ApiClient();
apiClient.setAdapterBuilder(adapterBuilder);
apiClient.getOkBuilder().addInterceptor(new UserAgentInterceptor(USER_AGENT));
TokenRequestBuilder tokenRequestBuilder = OAuthClientRequest.tokenLocation(OAUTH_TOKEN_URL)
.setScope(OAUTH_SCOPE).setClientId(OAUTH_CLIENT_ID).setClientSecret(OAUTH_CLIENT_SECRET)
.setUsername(username).setPassword(password);
OkHttpClient authHttpClient = new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor(USER_AGENT))
.build();
OAuth oauth = new OAuth(authHttpClient, tokenRequestBuilder);
oauth.setFlow(OAuthFlow.password);
apiClient.addAuthorization("oauth", oauth);
return apiClient.createService(PUBLICApi.class);
}
示例2: getTokenEndPoint
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
/**
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
* @return Token request builder
*/
public TokenRequestBuilder getTokenEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getTokenRequestBuilder();
}
}
return null;
}
示例3: OAuth
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
this.tokenRequestBuilder = requestBuilder;
}
示例4: getTokenEndPoint
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
/**
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
* @return Token request builder
*/
public TokenRequestBuilder getTokenEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getTokenRequestBuilder();
}
}
return null;
}
示例5: getTokenEndPoint
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
/**
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
* @return
*/
public TokenRequestBuilder getTokenEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getTokenRequestBuilder();
}
}
return null;
}
示例6: tokenAppOnly
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
/**
* Token retrieval (<i>app-only</i> flow).<br>
* <br>
* Retrieve a token for the <u>application-only</u>, meaning that the
* token is <u>not coupled to any user</u>. The token is typically only
* <u>valid for a short period of time</u> (at the moment of writing: 1 hour).
* After it has expired, the token will no longer work. You must request a <u>new</u>
* token in that case. Refreshing an application-only token is not possible.
*
* @param confidential <i>True</i>: confidential clients (web apps / scripts) not acting on
* behalf of one or more logged out users. <i>False</i>: installed app types,
* and other apps acting on behalf of one or more logged out users.
*
* @return Token (not associated with a user)
*
* @throws RedditOAuthException
*/
public synchronized RedditToken tokenAppOnly(boolean confidential) throws RedditOAuthException {
try {
// Set general values of the request
TokenRequestBuilder builder = OAuthClientRequest
.tokenProvider(OAuthProviderType.REDDIT)
.setParameter(PARAM_GRANT_TYPE, confidential ? GRANT_TYPE_CLIENT_CREDENTIALS : GRANT_TYPE_INSTALLED_CLIENT)
.setClientId(redditApp.getClientID())
.setClientSecret(redditApp.getClientSecret());
// If it is not acting on behalf of a unique client, a unique device identifier must be generated:
if (!confidential) {
builder = builder.setParameter(PARAM_DEVICE_ID, UUID.randomUUID().toString());
}
// Build the request
OAuthClientRequest request = builder.buildBodyMessage();
// Add the user agent
addUserAgent(request);
// Add basic authentication
addBasicAuthentication(request, redditApp);
// Return a wrapper controlled by jReddit
return new RedditToken(oAuthClient.accessToken(request));
} catch (OAuthSystemException oase) {
throw new RedditOAuthException(oase);
} catch (OAuthProblemException oape) {
throw new RedditOAuthException(oape);
}
}
示例7: login
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
@Authenticate
public static String login(String serverId, String code, String locales, String redirectBase)
{
try
{
String redirect = redirectBase + "/session/ologin";
OauthServer server = OauthServer.get(serverId);
/*
* Get the access token
*/
TokenRequestBuilder tokenBuilder = OAuthClientRequest.tokenLocation(server.getTokenLocation());
tokenBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
tokenBuilder.setClientId(server.getClientId());
tokenBuilder.setClientSecret(server.getSecretKey());
tokenBuilder.setRedirectURI(redirect);
tokenBuilder.setCode(code);
OAuthClientRequest tokenRequest = tokenBuilder.buildQueryMessage();
tokenRequest.setHeader("Accept", "application/json");
oAuthClient = new OAuthClient(new URLConnectionClient());
accessToken = oAuthClient.accessToken(tokenRequest);
/*
* Request the user information
*/
JSONObject object = resourceRequest(server.getProfileLocation());
SingleActorDAOIF profile = ExternalProfile.getOrCreate(server, object);
return SessionFacade.logIn(profile, LocaleSerializer.deserialize(locales));
}
catch (JSONException | OAuthSystemException | OAuthProblemException e)
{
throw new InvalidLoginException(e);
}
}
示例8: getTokenRequestBuilder
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
public TokenRequestBuilder getTokenRequestBuilder() {
return tokenRequestBuilder;
}
示例9: setTokenRequestBuilder
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; //导入依赖的package包/类
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
this.tokenRequestBuilder = tokenRequestBuilder;
}