# BaseAuth

{% hint style="warning" %}
This class is an interface, it shouldn't be created directly.
{% endhint %}

## Members

### `application :` [`Application`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/application)

The application that this object is associated with.

### `endpoint : string`

The Vulos Identity server endpoint URL.

## Methods

### `constructor(application, endpoint?)`

This should only get called by classes that inherit the `BaseAuth` class.

* `application` should be an instance of the [`Application`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/application) object.
* `endpoint` should be a string or a `false` value (like `null` or `undefined`) that represents the Vulos Identity endpoint.

```javascript
// the constructor is called inside of the createAuth method of `Application`
import { BackendAuth } from "@vulos/identity-node-sdk"
const auth = applicaion.createAuth(BackendAuth)
```

{% hint style="info" %}
See [`Application`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/application) for more information.
{% endhint %}

### `async connect()`

Connect the authentication object to the Vulos Identity servers.

{% hint style="warning" %}
This should get called before any other functions.
{% endhint %}

```javascript
await auth.connect()
```

### `createVerifier()`

Create a verifier that other functions would take as an argument (as `authVerifier`).

{% hint style="info" %}
A verifier is an object that contains some value that will be used to verify if the server's response is valid.
{% endhint %}

{% hint style="success" %}
It's recommended create one verifier per authentication request.
{% endhint %}

```javascript
const verifier = auth.createVerifier()
```

### `async createAuthUrl(authVerifier)`

Create an authentication/consent URL for a user.

```javascript
const url = await auth.createAuthUrl(verifier)
// redirect the user to the URL
```

### `async processCallback(authVerifier, params)`

Process the callback URL query parameters (or fragment parameters if using the implicit flow) to get a [`User`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/user) object.

```javascript
// req is an object that is supposed to be a HTTP request in this example
const user = await auth.processCallback(verifier, req.query)
```

### `async getUserInfo(accessToken)`

Get an [`UserInfo`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/userinfo) object using an access token provided by OpenID.

```javascript
const userInfo = await auth.getUserInfo()
```

{% hint style="warning" %}
This probably shouldn't get called directly, use [`User.info()`](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/user#async-info) instead.
{% endhint %}

### `async refreshTokens(refreshToken)`

Get a new OpenID token set using a refresh token.

```javascript
const { access_token, refresh_token, id_token, token_type, expires_at} 
    = await auth.refreshTokens(refreshToken)
```

{% hint style="warning" %}
This probably shouldn't get called directly, it's called automatically when needed.
{% endhint %}
