Skip to content

Wrong type definition for amr claim in parsed token #254

@fcucino

Description

@fcucino

Describe the bug

The TypeScript type definitions in keycloak-js (specifically in keycloak.d.ts) declare the amr (Authentication Methods References) claim as string | undefined, but Keycloak server actually returns it as a JSON array (string[]) per RFC 8176.

This causes TypeScript type mismatches / incorrect IntelliSense when accessing keycloak.tokenParsed.amr, even though the runtime value is correctly an array.

Version

keycloak-js 26.2.2

Expected behavior

Type definition is typed as an array of strings

Actual behavior

Type definition is typed as a string

How to Reproduce?

  1. Use Keycloak server (any recent version, e.g. 26.x) with an authentication flow that includes at least one authenticator reference, for example pwd in Username Password Form.
  2. Initialize keycloak-js adapter in a TypeScript project:
    import Keycloak from 'keycloak-js';
    
    const keycloak = new Keycloak(/* config */);
    await keycloak.init({ onLoad: true });
    await keycloak.login();
  3. Observe TypeScript error / warning when trying to use array methods:
    keycloak.tokenParsed?.amr.map((value) => console.log("AMR VALUE: ", value)); // TS error: Property 'map' does not exist on type 'string'
  4. After successful login, access the parsed token:
    console.log(keycloak.tokenParsed?.amr);           // runtime: ["pwd"]
    console.log(Array.isArray(keycloak.tokenParsed?.amr)); // true

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions