Pular para conteúdo

Emissão e validação de tokens

Atender as APIs /auth-provider/v1/control-plane/oauth2/*, /data-plane/oauth2/* e /data-plane/internal/emit-token.

%%{init: {"theme":"base","themeVariables":{"fontFamily":"Arial, sans-serif","fontSize":"16px","lineColor":"#64748b","primaryTextColor":"#172b4d"},"flowchart":{"htmlLabels":true,"useMaxWidth":true,"nodeSpacing":28,"rankSpacing":38,"padding":14,"curve":"linear","subGraphTitleMargin":{"top":12,"bottom":16}},"sequence":{"useMaxWidth":true,"actorMargin":28,"width":145,"height":45,"diagramMarginX":32,"diagramMarginY":12,"messageMargin":24,"wrap":true,"mirrorActors":false},"themeCSS":".edgeLabel, .edgeLabel p {background-color:var(--diagram-surface)!important;color:var(--diagram-text)!important}\n.cluster rect {fill:var(--diagram-group)!important;stroke:var(--diagram-line)!important}\n.cluster-label span, .cluster-label text {color:var(--diagram-text)!important;fill:var(--diagram-text)!important}\n.flowchart-link, .actor-line {stroke:var(--diagram-line)!important}\nmarker path {fill:var(--diagram-line)!important;stroke:var(--diagram-line)!important}\n.actor {fill:var(--diagram-domain)!important;stroke:var(--diagram-domain-border)!important}\ntext.actor, .messageText, .loopText, .labelText {fill:var(--diagram-text)!important}\n.messageLine0, .messageLine1, .loopLine {stroke:var(--diagram-line)!important}\n.labelBox {fill:var(--diagram-surface)!important;stroke:var(--diagram-line)!important}\n.note {fill:var(--diagram-async)!important;stroke:var(--diagram-async-border)!important}\n.noteText {fill:var(--diagram-text)!important}\n.nodeLabel, .nodeLabel p, .nodeLabel span {color:var(--diagram-text)!important}\n.node .nodeLabel, .node .nodeLabel p {font-size:17px;font-weight:600;line-height:1.4;text-align:center}\n.nodeLabel small {display:inline-block;margin-top:4px;font-size:15px;font-weight:400;line-height:1.4;color:var(--diagram-description)!important}\ntext.actor, text.actor tspan {font-size:17px;font-weight:600}\n.node.entry rect, .node.entry polygon, .node.entry path, .node.entry circle {fill:var(--diagram-entry)!important;stroke:var(--diagram-entry-border)!important}\n.node.domain rect, .node.domain polygon, .node.domain path, .node.domain circle {fill:var(--diagram-domain)!important;stroke:var(--diagram-domain-border)!important}\n.node.security rect, .node.security polygon, .node.security path, .node.security circle {fill:var(--diagram-security)!important;stroke:var(--diagram-security-border)!important}\n.node.store rect, .node.store polygon, .node.store path, .node.store circle {fill:var(--diagram-store)!important;stroke:var(--diagram-store-border)!important}\n.node.async rect, .node.async polygon, .node.async path, .node.async circle {fill:var(--diagram-async)!important;stroke:var(--diagram-async-border)!important}\n.node.external rect, .node.external polygon, .node.external path, .node.external circle {fill:var(--diagram-external)!important;stroke:var(--diagram-external-border)!important}\n text.actor tspan, .loopText tspan, .labelText tspan, .messageText tspan, .noteText tspan {fill:var(--diagram-text)!important}\n\n"}}%%
%%{init: {"sequence":{"width":180,"actorMargin":35,"messageMargin":24,"wrap":true}}}%%
sequenceDiagram
    actor C as Consumidor
    participant A as Auth Provider
    participant K as Keycloak
    participant O as Provedor OIDC
    C->>A: Emitir ou validar token
    alt Emissão
    A->>A: Validar formulário
    opt Emissão normal ou token interno fora do cache
    A->>K: client_credentials no realm
    K-->>A: Token
    end
    else Validação OAuth
    A->>A: Decodificar JWT e selecionar kid
    A->>O: Resolver discovery e JWKS quando necessário
    O-->>A: Chave
    A->>A: Validar assinatura e claims configurados
    end
    A-->>C: Token ou resultado

Resumo: Emissão OAuth normal consulta o emissor sem o cache de tokens internos. A emissão interna aceita somente client_credentials e usa o emissor com cache. Validação distingue OAUTH2_EXTERNAL (discovery) de OAUTH2_PROVIDED (JWKS informado); o provedor pode ser Keycloak.

Resultado: Token emitido ou validação concluída. Test-discovery consulta e valida metadados OIDC sem executar uma rota.

Alternativas relevantes: Tipo inválido, configuração ausente, assinatura/claims rejeitados e erros do emissor produzem erros próprios. Cache não substitui validação.

Fluxos do serviço · Catálogo funcional.

Referências de implementação

auth-provider / token

auth-provider / oidc

auth-provider / validator

auth-provider / token_test