// Path: src/main/java/org/dmfs/oauth2/client/OAuth2AccessToken.java
// public interface OAuth2AccessToken
// {
//     /**
//      * Returns the actual access token String.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence accessToken() throws ProtocolException;
// 
//     /**
//      * Returns the access token type.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence tokenType() throws ProtocolException;
// 
//     /**
//      * Returns whether the response also contained a refresh token.
//      *
//      * @return
//      */
//     public boolean hasRefreshToken();
// 
//     /**
//      * Returns the refresh token. Before calling this use {@link #hasRefreshToken()} to check if there actually is a refresh token.
//      *
//      * @return
//      *
//      * @throws NoSuchElementException
//      *         If the token doesn't contain a refresh token.
//      * @throws ProtocolException
//      */
//     public CharSequence refreshToken() throws ProtocolException;
// 
//     /**
//      * Returns the expected expiration date of the access token.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public DateTime expirationDate() throws ProtocolException;
// 
//     /**
//      * The scope this {@link OAuth2AccessToken} was issued for. May be an empty scope if the scope is not known.
//      *
//      * @return An {@link OAuth2Scope}.
//      *
//      * @throws ProtocolException
//      */
//     public OAuth2Scope scope() throws ProtocolException;
// 
//     /**
//      * Returns a value stored in the token response under the {@code parameterName}.
//      *
//      * @param parameterName
//      *         the key under which the value is stored in the response
//      */
//     public Optional<CharSequence> extraParameter(final String parameterName);
// }


import org.dmfs.httpessentials.HttpMethod;
import org.dmfs.httpessentials.client.HttpRequest;
import org.dmfs.httpessentials.client.HttpRequestEntity;
import org.dmfs.httpessentials.client.HttpResponse;
import org.dmfs.httpessentials.client.HttpResponseHandler;
import org.dmfs.httpessentials.converters.PlainStringHeaderConverter;
import org.dmfs.httpessentials.exceptions.ProtocolError;
import org.dmfs.httpessentials.exceptions.ProtocolException;
import org.dmfs.httpessentials.headers.BasicSingletonHeaderType;
import org.dmfs.httpessentials.headers.Headers;
import org.dmfs.oauth2.client.OAuth2AccessToken;
import java.io.IOException;
/*
 * Copyright 2016 dmfs GmbH
 *
 * 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 org.dmfs.oauth2.client.http.decorators;




/**
 * An {@link HttpRequest} decorator that adds a Bearer authorization header.
 *
 * @param <T>
 *         The type of the expected response.
 *
 * @author Marten Gajda
 */
public final class BearerAuthenticatedRequest<T> implements HttpRequest<T>
{
    // TODO: use a generic authorization header instead (once we have one)
    private final static BasicSingletonHeaderType<String> AUTHORIZATION_HEADER = new BasicSingletonHeaderType<String>(
            "Authorization",
            new PlainStringHeaderConverter());

// Path: src/main/java/org/dmfs/oauth2/client/OAuth2AccessToken.java
// public interface OAuth2AccessToken
// {
//     /**
//      * Returns the actual access token String.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence accessToken() throws ProtocolException;
// 
//     /**
//      * Returns the access token type.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence tokenType() throws ProtocolException;
// 
//     /**
//      * Returns whether the response also contained a refresh token.
//      *
//      * @return
//      */
//     public boolean hasRefreshToken();
// 
//     /**
//      * Returns the refresh token. Before calling this use {@link #hasRefreshToken()} to check if there actually is a refresh token.
//      *
//      * @return
//      *
//      * @throws NoSuchElementException
//      *         If the token doesn't contain a refresh token.
//      * @throws ProtocolException
//      */
//     public CharSequence refreshToken() throws ProtocolException;
// 
//     /**
//      * Returns the expected expiration date of the access token.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public DateTime expirationDate() throws ProtocolException;
// 
//     /**
//      * The scope this {@link OAuth2AccessToken} was issued for. May be an empty scope if the scope is not known.
//      *
//      * @return An {@link OAuth2Scope}.
//      *
//      * @throws ProtocolException
//      */
//     public OAuth2Scope scope() throws ProtocolException;
// 
//     /**
//      * Returns a value stored in the token response under the {@code parameterName}.
//      *
//      * @param parameterName
//      *         the key under which the value is stored in the response
//      */
//     public Optional<CharSequence> extraParameter(final String parameterName);
// }


// Path: src/main/java/org/dmfs/oauth2/client/http/decorators/BearerAuthenticatedRequest.java
import org.dmfs.httpessentials.HttpMethod;
import org.dmfs.httpessentials.client.HttpRequest;
import org.dmfs.httpessentials.client.HttpRequestEntity;
import org.dmfs.httpessentials.client.HttpResponse;
import org.dmfs.httpessentials.client.HttpResponseHandler;
import org.dmfs.httpessentials.converters.PlainStringHeaderConverter;
import org.dmfs.httpessentials.exceptions.ProtocolError;
import org.dmfs.httpessentials.exceptions.ProtocolException;
import org.dmfs.httpessentials.headers.BasicSingletonHeaderType;
import org.dmfs.httpessentials.headers.Headers;
import org.dmfs.oauth2.client.OAuth2AccessToken;
import java.io.IOException;

/*
 * Copyright 2016 dmfs GmbH
 *
 * 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 org.dmfs.oauth2.client.http.decorators;




/**
 * An {@link HttpRequest} decorator that adds a Bearer authorization header.
 *
 * @param <T>
 *         The type of the expected response.
 *
 * @author Marten Gajda
 */
public final class BearerAuthenticatedRequest<T> implements HttpRequest<T>
{
    // TODO: use a generic authorization header instead (once we have one)
    private final static BasicSingletonHeaderType<String> AUTHORIZATION_HEADER = new BasicSingletonHeaderType<String>(
            "Authorization",
            new PlainStringHeaderConverter());

    private final OAuth2AccessToken mAccessToken;