# Authentication

Provider API v0.6.6 · 2 operasjoner
Kilde: https://plasapi.com/no/provider/v0.6.6/authentication/

Ingen beskrivelse i spesifikasjonen.

## Revoke access token

`POST` `/authentication/oauth2/revoke` · `RevokeToken`

Revoke an access token.

### Eksempel på kall

**cURL**

```bash
curl -X POST "$PLAS_BASE_URL/authentication/oauth2/revoke" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'client_id=nordby-vendor-app' \
  --data-urlencode 'client_secret=9f2kQ7xLm4Vb8RtZ' \
  --data-urlencode 'token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MDIxODg3MyJ9.c2lnbmF0dXJl'
```

**JavaScript**

```javascript
const response = await fetch(`${process.env.PLAS_BASE_URL}/authentication/oauth2/revoke`, {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams({
    "client_id": "nordby-vendor-app",
    "client_secret": "9f2kQ7xLm4Vb8RtZ",
    "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MDIxODg3MyJ9.c2lnbmF0dXJl",
  }),
});
```

**Python**

```python
import os
import requests

response = requests.post(
    f"{os.environ['PLAS_BASE_URL']}/authentication/oauth2/revoke",
    headers={
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
    },
    data={
        "client_id": "nordby-vendor-app",
        "client_secret": "9f2kQ7xLm4Vb8RtZ",
        "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MDIxODg3MyJ9.c2lnbmF0dXJl",
    },
)
response.raise_for_status()
```

Verten og tokenet er miljøvariabler: `PLAS_BASE_URL` providerens adresse.

### Request body

`application/x-www-form-urlencoded` · valgfri

The token that we want to revoke.

[`RevokeTokenRequestBody`](https://plasapi.com/no/provider/v0.6.6/schemas/#RevokeTokenRequestBody)

### Svar

#### `200` Token was successfully revoked, or the token was invalid (i.e. it was already 'revoked').

Ikke noe innhold i svaret.

#### `400` The list of errors.

`Errors`

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

Eksempel (Generert fra skjemaet):

```json
{
  "errors": [
    {
      "code": 200103,
      "info": "200103: invalid/unsupported query parameter value"
    }
  ]
}
```

## Authenticate client

`POST` `/authentication/oauth2/token` · `AuthenticateClient`

Authenticate the client to obtain a token.

It is recommended that the returned token is a JWT as this can come in handy if any part of the API,
e.g. the search API, needs to be delegated to a third party.  
The JWT could be used to ensure that only authorized clients have access to the third party API.


### Eksempel på kall

**cURL**

```bash
curl -X POST "$PLAS_BASE_URL/authentication/oauth2/token" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'client_id=nordby-vendor-app' \
  --data-urlencode 'client_secret=9f2kQ7xLm4Vb8RtZ' \
  --data-urlencode 'grant_type=client_credentials'
```

**JavaScript**

```javascript
const response = await fetch(`${process.env.PLAS_BASE_URL}/authentication/oauth2/token`, {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams({
    "client_id": "nordby-vendor-app",
    "client_secret": "9f2kQ7xLm4Vb8RtZ",
    "grant_type": "client_credentials",
  }),
});
const data = await response.json();
```

**Python**

```python
import os
import requests

response = requests.post(
    f"{os.environ['PLAS_BASE_URL']}/authentication/oauth2/token",
    headers={
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
    },
    data={
        "client_id": "nordby-vendor-app",
        "client_secret": "9f2kQ7xLm4Vb8RtZ",
        "grant_type": "client_credentials",
    },
)
data = response.json()
```

Verten og tokenet er miljøvariabler: `PLAS_BASE_URL` providerens adresse.

### Request body

`application/x-www-form-urlencoded` · valgfri

The authentication client credentials.

[`AuthenticationClientCredentialsRequestBody`](https://plasapi.com/no/provider/v0.6.6/schemas/#AuthenticationClientCredentialsRequestBody)

### Svar

#### `200` Success

`AuthenticationClientResponseBody`

Eksempel (Generert fra skjemaet):

```json
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MDIxODg3MyJ9.c2lnbmF0dXJl",
  "expires_in": 1,
  "token_type": "Bearer"
}
```

#### `400` The list of errors.

`Errors`

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

Eksempel (Generert fra skjemaet):

```json
{
  "errors": [
    {
      "code": 200103,
      "info": "200103: invalid/unsupported query parameter value"
    }
  ]
}
```

#### `401` Unauthorized login.

Ikke noe innhold i svaret.

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)
