本文整理汇总了Java中com.google.api.client.auth.oauth2.CredentialStore类的典型用法代码示例。如果您正苦于以下问题:Java CredentialStore类的具体用法?Java CredentialStore怎么用?Java CredentialStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CredentialStore类属于com.google.api.client.auth.oauth2包,在下文中一共展示了CredentialStore类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteCredential
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
public OAuthFuture<Boolean> deleteCredential(final String userId,
final OAuthCallback<Boolean> callback, Handler handler) {
Preconditions.checkNotNull(userId);
final Future2Task<Boolean> task = new Future2Task<Boolean>(handler, callback) {
@Override
public void doWork() throws Exception {
LOGGER.info("deleteCredential");
CredentialStore store = mFlow.getCredentialStore();
if (store == null) {
set(false);
return;
}
store.delete(userId, null);
set(true);
}
};
// run the task in a background thread
submitTaskToExecutor(task);
return task;
}
示例2: createAndStoreCredential
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
/**
* Creates a new credential for the given user ID based on the given token
* response and store in the credential store.
*
* @param response OAuth 1.0a authorization token response
* @param userId user ID or {@code null} if not using a persisted credential
* store
* @return newly created credential
* @throws IOException
*/
public OAuthHmacCredential createAndStoreCredential(OAuthCredentialsResponse response,
String userId) throws IOException {
OAuthHmacCredential credential = new10aCredential(userId)
.setAccessToken(response.token)
.setTokenSharedSecret(response.tokenSecret);
CredentialStore credentialStore = getCredentialStore();
if (credentialStore != null) {
credentialStore.store(userId, credential);
}
if (credentialCreatedListener != null) {
credentialCreatedListener.onCredentialCreated(credential, response);
}
return credential;
}
示例3: CredentialFactory
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
@Inject
public CredentialFactory(CredentialStore credentialStore, HttpTransport httpTransport,
JsonFactory jsonFactory, @Named("clientId") String clientId,
@Named("clientSecret") String clientSecret) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.credentialStore = credentialStore;
this.httpTransport = httpTransport;
this.jsonFactory = jsonFactory;
}
示例4: AuthorizationCodeFlowFactory
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
@Inject
public AuthorizationCodeFlowFactory(CredentialStore credentialStore,
JsonFactory jsonFactory,
HttpTransport httpTransport,
@Named("clientId") String clientId,
@Named("clientSecret") String clientSecret,
@Named("scope") String scope) {
this.credentialStore = credentialStore;
this.httpTransport = httpTransport;
this.jsonFactory = jsonFactory;
this.clientId = clientId;
this.clientSecret = clientSecret;
this.scope = scope;
}
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:15,代码来源:AuthorizationCodeFlowFactory.java
示例5: authorizeUser
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
示例6: authorizeUser
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private static Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
示例7: setCredentialStore
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
@Beta
@Override
public Builder setCredentialStore(CredentialStore credentialStore) {
return (Builder) super.setCredentialStore(credentialStore);
}
示例8: configureServlets
import com.google.api.client.auth.oauth2.CredentialStore; //导入依赖的package包/类
@Override
protected void configureServlets() {
super.configureServlets();
serve("/").with(IndexServlet.class);
serve("/denied").with(DeniedServlet.class);
serve("/dfp").with(IndexServlet.class);
serveRegex("/[0-9]+").with(IndexServlet.class);
serve("/fetch").with(DfpServlet.class);
serve("/get").with(TaskDispatchServlet.class);
serve("/newnetwork").with(CreateNetworkServlet.class);
serve(REDIRECT_URL).with(OAuth2CallbackServlet.class);
MapBinder<String, Fetcher> mapbinder =
MapBinder.newMapBinder(binder(), String.class, Fetcher.class);
mapbinder.addBinding(DfpTags.AD_UNITS).to(AdUnitFetcher.class);
mapbinder.addBinding(DfpTags.COMPANIES).to(CompanyFetcher.class);
mapbinder.addBinding(DfpTags.CREATIVES).to(CreativeFetcher.class);
mapbinder.addBinding(DfpTags.CREATIVE_TEMPLATES).to(CreativeTemplateFetcher.class);
mapbinder.addBinding(DfpTags.CUSTOM_TARGETING_KEYS).to(CustomTargetingKeyFetcher.class);
mapbinder.addBinding(DfpTags.CUSTOM_TARGETING).to(CustomTargetingKeyAndValueFetcher.class);
mapbinder.addBinding(DfpTags.CUSTOM_TARGETING_VALUES).to(CustomTargetingValueFetcher.class);
mapbinder.addBinding(DfpTags.LINE_ITEM_CREATIVE_ASSOCIATIONS)
.to(LineItemCreativeAssociationFetcher.class);
mapbinder.addBinding(DfpTags.LINE_ITEMS).to(LineItemFetcher.class);
mapbinder.addBinding(DfpTags.NETWORKS).to(NetworkFetcher.class);
mapbinder.addBinding(DfpTags.ORDERS).to(OrderFetcher.class);
mapbinder.addBinding(DfpTags.ORDERS_LINE_ITEMS).to(OrderLineItemFetcher.class);
mapbinder.addBinding(DfpTags.PLACEMENTS).to(PlacementFetcher.class);
mapbinder.addBinding(DfpTags.PUBLISHER_QUERY_LANGUAGE).to(PublisherQueryLanguageFetcher.class);
mapbinder.addBinding(DfpTags.ROLES).to(RoleFetcher.class);
mapbinder.addBinding(DfpTags.USERS).to(UserFetcher.class);
// The application name reported to the DFP API. Defaulted to the App Engine Unique ID.
bind(String.class)
.annotatedWith(Names.named("applicationName")).toProvider(new Provider<String>() {
public String get() {
String version = UNKNOWN_VERSION;
Properties properties = new Properties();
try {
properties.load(getServletContext().getResourceAsStream(PROPERTIES_PATH));
version = properties.getProperty(VERSION_PROPERTY);
} catch (IOException e) {
log.log(Level.SEVERE, "Cannot fetch file from " + PROPERTIES_PATH, e);
}
return ApiProxy.getCurrentEnvironment().getAppId() + "/" + version;
}
});
if (CLIENT_ID == null || CLIENT_ID.equals("INSERT_CLIENT_ID_HERE")
|| CLIENT_SECRET == null || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
throw new IllegalArgumentException(
"Please input your client IDs or secret in your WEB-INF/appengine-web.xml file.");
}
bindConstant().annotatedWith(Names.named("clientId")).to(CLIENT_ID);
bindConstant().annotatedWith(Names.named("clientSecret")).to(CLIENT_SECRET);
bindConstant().annotatedWith(Names.named("scope")).to(SCOPE);
bindConstant().annotatedWith(Names.named("redirectUrl")).to(REDIRECT_URL);
bindConstant().annotatedWith(Names.named("expirationDelta")).to(EXPIRATION_DELTA);
bind(FetchService.class);
bind(AuthorizationCodeFlowFactory.class);
bind(CredentialFactory.class);
bind(CredentialStore.class).to(AppEngineCredentialStore.class);
bind(DfpServices.class);
bind(FetcherFactory.class);
bind(GoogleCredential.class);
bind(HttpTransport.class).to(NetHttpTransport.class);
bind(JsonFactory.class).to(JacksonFactory.class);
bind(ChannelService.class).toProvider(ChannelServiceProvider.class);
bind(MemcacheService.class).toProvider(MemcacheServiceProvider.class);
bind(UserService.class).toProvider(UserServiceProvider.class);
install(new GsonModule());
install(new ExternalModule());
}