# Authorizing Requests

In most cases, when sending requests to the DaaS services, the request includes a header that contains an authorization code. The authorization code is acquired by sending a request to DAE’s DaaS token service.

### Authorization API

| URL        | HTTP Verb | Functionality                                                            |
| ---------- | --------- | ------------------------------------------------------------------------ |
| /authorize | POST      | Login with posting credentials to get access and refresh JSON Web Tokens |

## Get accessToken and refreshToken

<mark style="color:green;">`POST`</mark> `https://api.disasteraware.com/authorize`

Login with posting credentials to get access and refresh JSON Web Tokens

#### Request Body

| Name            | Type   | Description      |
| --------------- | ------ | ---------------- |
| User credential | object | User credential. |

{% tabs %}
{% tab title="200 " %}

```
{
    "accessToken":"access.token.will.be.here",
    "refreshToken":"refresh.token.will.be.here"
}
```

{% endtab %}

{% tab title="401 " %}

```
Authentication failed.
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="cURL" %}

```
curl --location --request POST \
  'https://api.disasteraware.com/authorize' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "username":"your_username", 
    "password":"your_password"
  }'
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {
		URL url = new URL("https://api.disasteraware.com/authorize");
		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
		httpConn.setRequestMethod("POST");

		httpConn.setRequestProperty("Content-Type", "application/json");

		httpConn.setDoOutput(true);
		OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
		writer.write("{ \"username\":\"your_username\", \"password\":\"your_password\" }");
		writer.flush();
		writer.close();
		httpConn.getOutputStream().close();

		InputStream responseStream = httpConn.getResponseCode() / 100 == 2
				? httpConn.getInputStream()
				: httpConn.getErrorStream();
		Scanner s = new Scanner(responseStream).useDelimiter("\\A");
		String response = s.hasNext() ? s.next() : "";
		System.out.println(response);
	}
}

```

{% endtab %}

{% tab title="Node.js" %}

```javascript
var fetch = require('node-fetch');

fetch('https://api.disasteraware.com/authorize', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({ "username":"your_username", "password":"your_password" })
});

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$headers = array(
    'Content-Type' => 'application/json'
);
$data = '{ "username":"your_username", "password":"your_password" }';
$response = Requests::post('https://api.disasteraware.com/authorize', $headers, $data);

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'Content-Type': 'application/json',
}

data = '{ "username":"your_username", "password":"your_password" }'

response = requests.post('https://api.disasteraware.com/authorize', headers=headers, data=data)

```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Please use the provided credentials to complete this request. The response will include a JSON Web Token (JWT) that you will send with the Authorization request header in the following format:

```
{
    "Authorization": "Bearer <insert-json-web-token>"
}
```

For more information about JWT please visit [jwt.io](https://jwt.io/)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.disasteraware.com/authentication/authorizing-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
