> 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/swe/api-dokumentation/auktorisering-apikey-autentiseringsuppgifter-eller-oauth-2.0.md).

# Auktorisering: ApiKey, autentiseringsuppgifter eller OAuth 2.0

GeoPard-lösningen använder [AWS Cognito](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) för autentiseringsproceduren.

Vi rekommenderar att kontrollera alla auktoriseringsalternativ. Valet beror på det specifika användningsfallet. Mer användningsdetaljer beskrivs i varje alternativ nedan.

## Alternativ 1: Använda referenser

Auktorisering med ”användarnamn” och ”lösenord” är en av de möjliga metoderna. I detta fall måste e-postregistrering göras (inte via sociala nätverk).&#x20;

{% hint style="info" %}
Tillvägagångssättet ***rekommenderas för integration på API (BackEnd)-nivå*** och alla förfrågningar till GeoPard API proxas via en dedikerad specialtjänst (mikrotjänst).
{% endhint %}

### Inloggningsförfrågan&#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 %}

### Inloggningssvar

{% hint style="danger" %}
Token är en JWT med en livslängd på 30 minuter.\
\
Det är bästa praxis att lagra en enda token och återanvända den i alla förfrågningar, kontrollera dess utgångstid och hämta en ny token när den löper ut (eller strax innan).
{% endhint %}

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

## Alternativ 2: OAuth 2.0

AWS Cognito stöder OAuth 2.0-protokollet för auktorisering. En allmän översikt beskrivs i artikeln [Cognito OAuth2-handbok](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), underartikeln Authorization Code Grant är mest intressant i GeoPard-fallet.&#x20;

{% hint style="info" %}
Tillvägagångssättet ***rekommenderas för att integrera GeoPard på användargränssnittet (FrontEnd)-nivå***. Integrationen fungerar i båda riktningarna för att skicka/motta data till/från GeoPard.
{% endhint %}

Kortfattat:

1. Din applikation måste omdirigera en användare till GeoPard Cognito för inloggning eller registrering.&#x20;

Exempel:

{% 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 %}

Vänligen kontakta GeoPard-teamet för att få din applikations individuella `client_id`.

2. Den omdirigerade URL:en kommer att ta emot en verifierings `kod` för nästa steg.

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

3. Din applikation måste byta ut `kod` för `tokens` (`access_token`, `refresh_token`, `id_token`).

Exempel:

{% 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-nyckel

Snabb åtkomst till WMS och WFS är ibland nödvändig. Därför är det möjligt att använda GeoPards API-nyckel som automatiskt genereras för varje konto.

API-nyckeln finns i `apiKey` attributet i GraphQL-entiteten "UserData". Instruktioner om hur man hämtar  `apiKey` ges [HÄR](/geopard-tutorials/swe/api-dokumentation/oversikt-over-geopard-api-begaranden/38.-fraga-hamta-userdata.md).

{% hint style="danger" %}
`apiKey` måste användas med `/geo` endpoints ENDAST.
{% endhint %}

Användning:

1. Som en `geopardApiKey` parameter i GET-förfrågans URL.
2. Som en `X-API-Key` header i VALFRI förfrågan.<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/swe/api-dokumentation/auktorisering-apikey-autentiseringsuppgifter-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.
