# Auth

{% hint style="info" %}
**If you would like to get familiar with the authentication flow, please click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.**
{% endhint %}

## Retrieves nonce for authentication

<mark style="color:blue;">`GET`</mark> `https://gateway-relay.herokuapp.com/auth/{wallet_address}/nonce`

#### Path Parameters

| Name                                              | Type   | Description              |
| ------------------------------------------------- | ------ | ------------------------ |
| wallet\_address<mark style="color:red;">\*</mark> | string | address of the user's UP |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" %}

```javascript
{
    nonce: 1955258057868615
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request malformed request error" %}
{% code title="Example 400 Response" overflow="wrap" %}

```javascript
{
    error: 'Malformed request, please ensure the following parameters are included: wallet_address'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Validate signature to authenticate user and provide jwt token

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/auth/{wallet_address}/signature`

#### Path Parameters

| Name                                              | Type   | Description              |
| ------------------------------------------------- | ------ | ------------------------ |
| wallet\_address<mark style="color:red;">\*</mark> | string | address of the user's UP |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    success: true,
    token: 'Bearer eyJh...LoYI', //full jwt token will go here
    expiresIn: '6h'
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request malformed request error" %}
{% code title="Example 400 Response" overflow="wrap" %}

```javascript
{
    error: 'Malformed request, please ensure the following parameters are included: wallet_address'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized invalid credentials error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Invalid Credentials! Ensure the account you are using to sign this message is the same as the one that received the nonce.'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
