All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.api.client.googleapis.auth.oauth.GoogleOAuthDomainWideDelegation Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.api.client.googleapis.auth.oauth;

import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.googleapis.GoogleUrl;
import com.google.api.client.http.HttpExecuteIntercepter;
import com.google.api.client.http.HttpExecuteInterceptor;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.util.Key;

import java.io.IOException;

/**
 * Google's OAuth domain-wide delegation requires an e-mail address of the user whose data you are
 * trying to access via {@link #requestorId} on every HTTP request.
 *
 * 

* Sample usage, taking advantage that this class implements {@link HttpRequestInitializer}: *

* *
  public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
    GoogleOAuthDomainWideDelegation initializer = new GoogleOAuthDomainWideDelegation();
    initializer.requestorId = "...";
    OAuthParameters parameters = new OAuthParameters();
    // parameters...
    initializer.parameters = parameters;
    return transport.createRequestFactory(initializer);
  }
 * 
* *

* If you have a custom request initializer, take a look at the sample usage for * {@link HttpExecuteInterceptor}, which this class also implements. *

* * @since 1.0 * @author Yaniv Inbar */ @SuppressWarnings("deprecation") public final class GoogleOAuthDomainWideDelegation implements HttpExecuteInterceptor, HttpExecuteIntercepter, HttpRequestInitializer { /** * Generic URL that extends {@link GoogleUrl} and also provides the {@link #requestorId} * parameter. */ public static final class Url extends GoogleUrl { /** Email address of the user whose data you are trying to access. */ @Key("xoauth_requestor_id") public String requestorId; /** * @param encodedUrl encoded URL, including any existing query parameters that should be parsed */ public Url(String encodedUrl) { super(encodedUrl); } } /** Email address of the user whose data you are trying to access. */ public String requestorId; /** * OAuth parameters. * * @since 1.4 */ public OAuthParameters parameters; public void initialize(HttpRequest request) { request.interceptor = this; } @SuppressWarnings("deprecation") public void intercept(HttpRequest request) throws IOException { request.url.set("xoauth_requestor_id", requestorId); if (parameters != null) { parameters.intercept(request); } } /** * Performs OAuth HTTP request signing via query parameter for the {@code xoauth_requestor_id} and * the {@code Authorization} header as the final HTTP request execute intercepter for the given * HTTP request execute manager. * * @param transport HTTP transport * @param parameters OAuth parameters; the {@link OAuthParameters#signer} and * {@link OAuthParameters#consumerKey} should be set * @deprecated (scheduled to be removed in 1.5) Use {@link GoogleOAuthDomainWideDelegation} * directly */ @Deprecated public void signRequests(HttpTransport transport, OAuthParameters parameters) { transport.intercepters.add(this); parameters.signRequestsUsingAuthorizationHeader(transport); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy