> 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/svn/api-dokumentacija/avtorizacija-apikey-credentials-ali-oauth-2.0.md).

# Avtorizacija: ApiKey, Credentials ali OAuth 2.0

Rešitev GeoPard uporablja [AWS Cognito](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) za postopek avtentikacije.

Priporočamo, da preverite vse možnosti avtorizacije. Izbira je odvisna od konkretnega primera uporabe. Več podrobnosti o uporabi je opisano pri vsaki spodnji možnosti.

## Možnost 1: Uporaba poverilnic

Avtorizacija z »uporabniškim imenom« in »geslom« je ena izmed možnih pristopov. V tem primeru se mora registracija po e-pošti opraviti (ne z uporabo družbenih omrežij).&#x20;

{% hint style="info" %}
Pristop ***je priporočljiv za integracijo na ravni API (BackEnd)*** in so vsi zahtevki do GeoPard API posredovani prek namenske posebne storitve (mikrostoritve).
{% endhint %}

### Zahteva za prijavo&#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 %}

### Odgovor na prijavo

{% hint style="danger" %}
Token je JWT z življenjsko dobo 30 minut.\
\
Najboljša praksa je shraniti en sam token in ga ponovno uporabiti v vseh zahtevkih, preverjati njegov čas poteka in pridobiti nov token, ko poteče (ali kmalu pred tem).
{% endhint %}

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

## Možnost 2: OAuth 2.0

AWS Cognito podpira protokol OAuth 2.0 za avtorizacijo. Splošen pregled je opisan v članku [Cognito OAuth2 priročnik](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), podčlanek Authorization Code Grant pa je v primeru GeoPard najbolj zanimiv.&#x20;

{% hint style="info" %}
Pristop ***je priporočljivo integrirati GeoPard na raven uporabniškega vmesnika (FrontEnd)***. Integracija deluje v obe smeri za pošiljanje/prejemanje podatkov v/iz GeoPard.
{% endhint %}

Na kratko:

1. Vaša aplikacija mora preusmeriti uporabnika na GeoPard Cognito za prijavo ali registracijo.&#x20;

Primer:

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

Prosimo, povežite se z ekipo GeoPard, da prejmete svoj aplikaciji lasten `client_id`.

2. Preusmerjeni URL bo prejel verifikacijsko `kodo` za naslednji korak.

Preusmerjeni URL izgleda takole [`http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a&state=54321`](http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a\&state=54321).

3. Vaša aplikacija mora zamenjati `kodo` za `tokene` (`access_token`, `refresh_token`, `id_token`).

Primer:

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

## Možnost 3: API ključ

Hiter dostop do WMS in WFS je občasno potreben. Zato je mogoče uporabiti GeoPard API ključ, ki se samodejno ustvari za vsak račun.

API ključ lahko najdete v `apiKljuč` atributu entitete GraphQL »UserData«. Navodila, kako pridobiti  `apiKljuč` so zagotovljena [TUKAJ](/geopard-tutorials/svn/api-dokumentacija/pregled-zahtevkov-api-ja-geopard/38.-poizvedba-pridobi-userdata.md).

{% hint style="danger" %}
`apiKljuč` mora se uporabljati z `/geo` končnimi točkami SAMO.
{% endhint %}

Uporaba:

1. Kot `geopardApiKey` parameter v URL-ju GET zahteve.
2. Kot `X-API-Key` glava v KATERIKOLI zahtevi.<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/svn/api-dokumentacija/avtorizacija-apikey-credentials-ali-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.
