# Class BasicAuthentication (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BasicAuthentication)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.BasicAuthentication)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.BasicAuthentication)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.BasicAuthentication)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.BasicAuthentication)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.BasicAuthentication)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.BasicAuthentication)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.BasicAuthentication)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.BasicAuthentication)

    public final class BasicAuthentication implements HttpRequestInitializer, HttpExecuteInterceptor

Basic authentication HTTP request initializer as specified in [Basic Authentication Scheme](http://tools.ietf.org/html/rfc2617#section-2)

Implementation is immutable and thread-safe. It can be used as either an HTTP request
initializer or an HTTP request execute interceptor. [#initialize(HttpRequest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BasicAuthentication#com_google_api_client_http_BasicAuthentication_initialize_com_google_api_client_http_HttpRequest_) only sets
itself as the interceptor. Authentication is actually done in [#intercept(HttpRequest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BasicAuthentication#com_google_api_client_http_BasicAuthentication_intercept_com_google_api_client_http_HttpRequest_),
which is implemented using [HttpHeaders#setBasicAuthentication(String, String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpHeaders#com_google_api_client_http_HttpHeaders_setBasicAuthentication_java_lang_String_java_lang_String_).

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> BasicAuthentication

## Implements

[HttpRequestInitializer](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequestInitializer), [HttpExecuteInterceptor](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpExecuteInterceptor)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### BasicAuthentication(String username, String password)

    public BasicAuthentication(String username, String password)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `username` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `password` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

## Methods

### getPassword()

    public String getPassword()

Returns the password.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getUsername()

    public String getUsername()

Returns the username.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### initialize(HttpRequest request)

    public void initialize(HttpRequest request)

Initializes a request.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequest` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### intercept(HttpRequest request)

    public void intercept(HttpRequest request)

Invoked at the start of [HttpRequest#execute()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequest#com_google_api_client_http_HttpRequest_execute__) before executing the HTTP request.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequest` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |