> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/caf-docs/caf-product-guides-pt-br/guia-do-usuario/smart-auth/checking-the-response.md).

# Verificando a resposta

Para garantir a integridade dos resultados do Smart Auth SDK, as informações de retorno são incluídas em uma carga útil dentro de um JSON Web Token (JWT) assinado usando seu `clientSecret`. Esse token é chamado de um **atestado** e deve ser enviado ao seu backend e verificado antes de conceder ao usuário acesso ao seu sistema.

Além do atestado quando isAuthorized é true, que contém o attemptId dentro do token, também há um caso em que isAuthorized é false. Nesse cenário, o attemptId é retornado junto com o campo isAuthorized.

Certifique-se de que tanto o atestado quanto o attemptId (quando aplicável) sejam tratados e verificados corretamente em seu sistema de backend.

## **Como verificar a resposta sem JWT (atestado)**

Nos casos em que o atestado não está presente na resposta, você receberá um objeto com dois campos: isAuthorized e attemptId.

```javascript
const response = 'response from sdk';
console.log(response);

/* Registro:
{
    attemptId: "6018d4da5ea6db000849a669",
    isAuthorized: false
}
*/
```

O campo attemptId pode ser usado para capturar dados sobre a tentativa de autenticação. Para mais informações, consulte [aqui](https://docs.caf.io/caf-api/smart-auth-api/available-resources/authentications).

## **Como obter seu `clientSecret`**

Veja [a documentação](https://docs.caf.io/caf-docs/caf-product-guides-pt-br/guia-do-usuario/smart-auth/access-token.md) sobre tokens de acesso do Smart Auth.

## **Validação de JWT**

Para a validação do usuário, usamos o token JWT retornado.

A partir dele, pegamos os dados necessários para a validação (**`isAuthorized`** e **`isNewContext`**).

### **Dados inseridos no JWT (atestado)**

| Campo              | Tipo     | Descrição                                                              |
| ------------------ | -------- | ---------------------------------------------------------------------- |
| **`attemptId`**    | string   | ID da tentativa de autenticação                                        |
| **`peopleId`**     | string   | CPF do usuário autenticado                                             |
| **`policyId`**     | string   | ID da política validada                                                |
| **`isAuthorized`** | booleano | Indica se o usuário foi autorizado de acordo com as regras da política |
| **`isNewContext`** | booleano | Indica se o contexto do usuário já era conhecido                       |

### **Como extrair dados do JWT**

```javascript
import jwt from 'jsonwebtoken';

const attestation = 'atestado recebido do SDK';
const secret = 'segredo do seu usuário';
const attestationData = jwt.verify(attestation, secret);

console.log(attestationData);
/* Registro:
{
    attemptId: "6018d4da5ea6db000849a669"
    exp: 1612240210
    iat: 1612240090
    isAuthorized: true
    isNewContext: false
    peopleId: "[cpf]"
    policyId: "[id da política]"
}
*/
```

### **Verificação de autorização**

<pre class="language-javascript"><code class="lang-javascript">const { isAuthorized, isNewContext } = attestationData;

if(isAuthorized &#x26;&#x26; !isNewContext) {
<strong>    // usuário autorizado sem necessidade de verificação
</strong>} else if(isAuthorized &#x26;&#x26; isNewContext) {
    // usuário autorizado após verificação
}
</code></pre>


---

# 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.caf.io/caf-docs/caf-product-guides-pt-br/guia-do-usuario/smart-auth/checking-the-response.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.
