> 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/it/documentazione-api/autorizzazione-apikey-credentials-oppure-oauth-2.0.md).

# Autorizzazione: ApiKey, Credentials oppure OAuth 2.0

La soluzione GeoPard utilizza [AWS Cognito](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/what-is-amazon-cognito.html) per la procedura di autenticazione.

Raccomandiamo di verificare tutte le opzioni di autorizzazione. La scelta dipende dal caso d'uso specifico. Maggiori dettagli sull'utilizzo sono descritti per ogni opzione di seguito.

## Opzione 1: Utilizzo di credenziali

L'autorizzazione con “username” e “password” è uno degli approcci possibili. In questo caso, la registrazione tramite email deve essere effettuata (non usando i social network).&#x20;

{% hint style="info" %}
L'approccio ***è raccomandato per l'integrazione a livello di API (BackEnd)*** e tutte le richieste all'API GeoPard sono proxyfiate tramite un servizio dedicato (microservizio).
{% endhint %}

### Richiesta di login&#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 %}

### Risposta al login

{% hint style="danger" %}
Il token è un JWT con una durata di 30 minuti.\
\
È buona pratica memorizzare un singolo token e riutilizzarlo per tutte le richieste, controllando il tempo di scadenza e ottenendo un nuovo token quando scade (o poco prima).
{% endhint %}

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

## Opzione 2: OAuth 2.0

AWS Cognito supporta il protocollo OAuth 2.0 per l'autorizzazione. Una panoramica generale è descritta nell'articolo [Manuale Cognito OAuth2](https://aws.amazon.com/ru/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/), il sotto-articolo Authorization Code Grant è il più interessante nel caso GeoPard.&#x20;

{% hint style="info" %}
L'approccio ***è consigliato integrare GeoPard a livello di interfaccia utente (FrontEnd)***. L'integrazione funziona in entrambe le direzioni per inviare/ricevere dati verso/da GeoPard.
{% endhint %}

Per farla breve:

1. La tua applicazione deve reindirizzare un utente a GeoPard Cognito per il login o la registrazione.&#x20;

Esempio:

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

Per favore, collegati con il team GeoPard per ricevere il tuo `client_id`.

2. L'URL di reindirizzamento riceverà una verifica `code` per il passo successivo.

L'URL di reindirizzamento appare come [`http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a&state=54321`](http://localhost:8080/?code=eb10956a-6d51-49e5-bbfe-9815e3fdc70a\&state=54321).

3. La tua applicazione deve scambiare `code` per `tokens` (`access_token`, `refresh_token`, `id_token`).

Esempio:

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

## Opzione 3: Chiave API

L'accesso rapido a WMS e WFS è necessario di tanto in tanto. Pertanto, è possibile utilizzare la chiave API di GeoPard generata automaticamente per ogni account.

La chiave API può essere trovata nell' `chiaveApi` attributo dell'entità GraphQL "UserData". Le istruzioni su come recuperare  `chiaveApi` sono fornite [QUI](/geopard-tutorials/it/documentazione-api/panoramica-delle-richieste-dellapi-geopard/38.-query-recupera-userdata.md).

{% hint style="danger" %}
`chiaveApi` deve essere utilizzata con `/geo` endpoint SOLO.
{% endhint %}

Utilizzo:

1. Come `geopardApiKey` parametro nell'URL della richiesta GET.
2. Come `intestazione X-API-Key` in QUALSIASI richiesta.<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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.geopard.tech/geopard-tutorials/it/documentazione-api/autorizzazione-apikey-credentials-oppure-oauth-2.0.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
