> For the complete documentation index, see [llms.txt](https://docs.geopard.tech/geopard-tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.geopard.tech/geopard-tutorials/nor/api-dokumentasjon/autorisering-apikey-legitimasjon-eller-oauth-2.0.md).

# Autorisering: ApiKey, legitimasjon eller OAuth 2.0

GeoPard-løsningen bruker [AWS Cognito](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) for autentiseringsprosedyren.

Vi anbefaler å sjekke alle autorisasjonsalternativer. Valget avhenger av den konkrete bruken. Flere bruksdetaljer er beskrevet i hvert alternativ nedenfor.

## Alternativ 1: Bruke legitimasjon

Autorisering med “brukernavn” og “passord” er en av mulige tilnærminger. I dette tilfellet må e-postregistrering gjøres (ikke bruke sosiale nettverk).&#x20;

{% hint style="info" %}
Tilnærmingen ***anbefales for integrasjon på API (BackEnd)-nivå*** og alle forespørsler til GeoPard API blir videresendt via en dedikert spesialtjeneste (mikrotjeneste).
{% endhint %}

### Innloggingsforespørsel&#x20;

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request POST 'https://api.geopard.tech/login' \
--header 'Content-Type: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{"username":"<email_address>","password":"<password>"}'
```

{% endcode %}

### Innloggingssvar

{% hint style="danger" %}
Tokenet er en JWT med levetid på 30 minutter.\
\
Det er beste praksis å lagre ett enkelt token og gjenbruke det i alle forespørsler, sjekke utløpstidspunktet og hente et nytt token når det utløper (eller kort tid før).
{% endhint %}

```json
{
    "token": "<token_to_use_in_geopard_api>"
}
```

## Alternativ 2: OAuth 2.0

AWS Cognito støtter OAuth 2.0-protokollen for autorisering. Den generelle oversikten er beskrevet i artikkelen [Cognito OAuth2-manual](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), underartikkelen Authorization Code Grant er mest interessant i GeoPard-tilfelle.&#x20;

{% hint style="info" %}
Tilnærmingen ***anbefales å integrere GeoPard på brukergrensesnittet (FrontEnd)-nivå***. Integrasjonen fungerer i begge retninger for å sende/motta data til/fra GeoPard.
{% endhint %}

For å gjøre historien kort:

1. Applikasjonen din må sende brukeren til GeoPard Cognito for innlogging eller registrering.&#x20;

Eksempel:

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request GET '
https://auth.geopard.tech/oauth2/authorize?response_type=code&client_id=<connect_geopard_team>&redirect_uri=http://localhost:8080&state=54321
'
```

{% endcode %}

Vennligst kontakt GeoPard-teamet for å motta din applikasjons individuelle `client_id`.

2. Den omdirigerte URL-en vil motta en verifiserings `kode` for neste steg.

Den omdirigerte URL-en ser slik ut [`http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a&state=54321`](http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a\&state=54321).

3. Applikasjonen din må bytte ut `kode` for `tokens` (`access_token`, `refresh_token`, `id_token`).

Eksempel:

{% code overflow="wrap" lineNumbers="true" %}

```bash
curl --location --request POST '
https://auth.geopard.tech/oauth2/token
' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: XSRF-TOKEN=365e14e1-3c66-477e-b0ef-a9e436a834ee; csrf-state=""; csrf-state-legacy=""' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a' \
--data-urlencode 'client_id=42ajne9u466in6gaf569nth9o9' \
--data-urlencode 'redirect_uri="
http://localhost:8080
'
```

{% endcode %}

## Alternativ 3: API-nøkkel

Rask tilgang til WMS og WFS er nødvendig av og til. Derfor er det mulig å bruke GeoPard API-nøkkelen som automatisk genereres for hver konto.

API-nøkkelen kan finnes i `apiNøkkel` attributtet til "UserData" GraphQL-entiteten. Instruksjoner om hvordan du henter  `apiNøkkel` er gitt [HER](/geopard-tutorials/nor/api-dokumentasjon/oversikt-over-foresporsler-i-geopard-api-et/38.-sporring-hent-userdata.md).

{% hint style="danger" %}
`apiNøkkel` må brukes med `/geo` endepunkter KUN.
{% endhint %}

Bruk:

1. Som en `geopardApiKey` parameter i GET-forespørselens URL.
2. Som en `X-API-Key` header i HVILKEN SOM HELST forespørsel.<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.geopard.tech/geopard-tutorials/nor/api-dokumentasjon/autorisering-apikey-legitimasjon-eller-oauth-2.0.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
