API
Introduction
The System API uses authentication based on JWTs (JSON Web Tokens), a self-contained method that does not require storage of token indexes or other storage forms.
Token types
API flows
Authentication Flow
sequenceDiagram
participant Client as API Client
participant Auth as Authentication Endpoint
participant API as API
Client->>Auth: Assina o JWT e envia ao Auth Endpoint
Auth->>Auth: Decodifica o JWT e verifica a assinatura
alt JWT Válido
Auth->>Client: Cria e envia um JWT de acesso
Client->>API: Armazena o JWT e utiliza no acesso à API
API->>API: Verifica a autenticidade do token
alt Token Válido
API->>Client: Libera acesso e envia ao API Client
else Token Inválido
API->>API: Fim
end
else JWT Inválido
Auth->>Auth: Fim
end
Client->>Client: Finaliza a requisição
Refresh flow
sequenceDiagram
participant Client as API Client
participant Auth as Authentication Endpoint
participant API as API
alt Token próximo de expirar?
Client->>Auth: Envia um JWT de autorização ainda não expirado
Auth->>Auth: Verifica a autenticidade do token
alt Token Válido
Auth->>Client: Cria e envia um JWT de acesso
Client->>Client: Armazena o JWT para uso
else Token Inválido
Auth->>Auth: Fim
end
else Token não próximo de expirar
Client->>API: Utiliza o token e envia a requisição
API->>API: Verifica a autenticidade do token
alt Token Válido
API->>Client: Libera acesso e envia resposta
else Token Inválido
API->>API: Fim
end
end
Client->>Client: Finaliza a requisição
Tokens have configurable expiration time (maximum 24h). Valid tokens can be used to order new tokens via refresh.
Final considerations
The implementation of JWTs provides a secure and efficient authentication method, eliminating the need for state storage on the server. The refresh system allows you to keep active sessions secure, while the 24-hour limit ensures periodic renewal of credentials.
