# Authenticatie

### API geheime sleutel ophalen

De Dastra API Rest gebruikt API-sleutels om elk verzoek te authenticeren. U kunt uw sleutels beheren in de[ configuratie-interface van uw organisatie](https://app.dastra.eu/general-settings/api).

U kunt een API-sleutel gebruiken voor een specifieke werkruimte of voor de hele organisatie.

Met uw API-sleutel kunt u veel dingen doen en daarom moet u deze veilig bewaren. Deel je geheime sleutel niet in de openbare delen van applicaties zoals GitHub, client code, etc.

Als je OAuth2 authenticatie in de "authorization\_code" modus wilt gebruiken, dan moet je de omleiding url('s) en de geauthoriseerde COR's origins configureren.

![](/files/HmwDWeRtZIzuzsiPiuWc)

## OAuth2 "Autorisatie code" stroom

### Autorisatie

de autorisatie fase wordt uitgevoerd door de volgende url aan te roepen:

```
https://account.dastra.eu/connect/authorize?
    response_type=code&
    client_id={YOUR_CLIENT_ID}&
    redirect_uri=https://YOUR_APP/callback&
    scope=api1+offline_access&
    state={STATE}
```

**Parameters**

<table><thead><tr><th width="272.5595168190588">Parameter Name</th><th width="470.9578998488362">Beschrijving</th></tr></thead><tbody><tr><td><code>response_type</code></td><td>code</td></tr><tr><td><code>client_id</code></td><td>De openbare sleutel van uw api-sleutel die is geconfigureerd in uw Dastra-account</td></tr><tr><td><code>redirect_uri</code></td><td>De url die is geconfigureerd in de Dastra API-sleutel. U wordt automatisch doorgestuurd naar deze pagina aan het einde van het autorisatieproces</td></tr><tr><td><code>scope</code></td><td><p>api1 => mandatory</p><p>offline_access <em>=></em> om een refresh_token op te halen (lange sessies)</p></td></tr><tr><td><code>state</code></td><td>Een willekeurige sleutel die wordt gegenereerd door uw applicatie om cross- site request forgery (CSRF)-aanvallen voorkomt, lees <a href="https://auth0.com/docs/protocols/oauth2/mitigate-csrf-attacks">Mitigate CSRF Attacks With State Parameters</a>. Clientbibliotheken kunnen dit snel afhandelen</td></tr></tbody></table>

## OAuth2 "Client credential" stroom

### Authenticatiemethode

De API wordt geauthenticeerd met behulp van het \[OAuth2 protocol] (<https://oauth.net/2/>) met behulp van de "Client credential" stroom. Deze authenticatiemethode mag alleen worden gebruikt voor server-naar-serververzoeken en mag nooit aan de browserzijde worden gebruikt (SPA in javascript bijvoorbeeld).

![](https://github.com/Dastrateam/dastra-doc-nl/blob/main/.gitbook/assets/API%20authenticatie%20scheam.svg)

### Het token herstellen

<mark style="color:green;">`POST`</mark> `https://account.dastra.eu/connect/token`

Voer een tokenverzoek uit met BASIC-headers

Als je eenmaal een toegangstoken hebt opgehaald, kun je elk Rest API endpoint aanroepen met dit toegangstoken door het als een "Bearer token" \&#x20 door te geven;

Bijvoorbeeld, om de lijst van je workspaces op te halen :

<mark style="color:blue;">`GET`</mark> `https://api.dastra.eu/v1/workspaces`

Verkrijg de lijst van Dastra workspaces

#### Headers

| Name                               | Type          | Description            |
| ---------------------------------- | ------------- | ---------------------- |
| <mark style="color:red;">\*</mark> | Authorization | Bearer {access\_token} |

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

```javascript
{
  "items": [
    {
      "id": 1,
      "huurderId": 1,
      "label": "Mijn gegevens bedrijf",
      "logoUrl": null,
      "status": "Activa",
      "permissies": null,
      "dataSubjectArchivedRetentionDays": null,
      "nbEntities": 1
    },
    {
      "id": 2,
      "tenantId": 1,
      "label": "Mijn testwerkruimte",
      "logoUrl": null,
      "status": "Activa",
      "permissies": null,
      "dataSubjectArchivedRetentionDays": null,
      "nbEntities": 1
    },
    {
      "id": 3,
      "tenantId": 1,
      "label": "Mijn experimenteerwerkruimte",
      "logoUrl": null,
      "status": "Activa",
      "permissies": null,
      "dataSubjectArchivedRetentionDays": null,
      "nbEntities": 0
    }
  ],
  "total": 3
}
```

{% endtab %}
{% endtabs %}

Alle verzoeken moeten worden gedaan via [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure) en altijd aan de serverkant. Verzoeken zonder authenticatie zullen mislukken met foutcode 401.

Zie de API referenties hier: <https://api.dastra.eu/swagger/index.html>^.


---

# 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://doc.dastra.eu/nl/api-references/authentification.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.
