okta / okta-mobile-swift

okta-mobile-swift
https://github.com/okta/okta-mobile-swift
Apache License 2.0
44 stars 19 forks source link

Extend Token with `HasClaims` for custom claims #204

Closed mikenachbaur-okta closed 2 months ago

mikenachbaur-okta commented 3 months ago

The IETF RFCs for Tokens not only include a couple extra properties that were not previously addressed, but it states that the responses may be extended with custom information. Authorization servers, such as Keycloak, includes metadata in the token response indicating refresh token expiration, or other data.

Since Token responses can be extended, it stands to reason that these objects should conform to HasClaims just like other models, to allow for them to be adapted to different authentication scenarios.

This update further extends the support for Claims to resolve edge-cases in how convertible values were handled, unifying support around mapping claims to scalar values, arrays, or dictionaries, and cleaning up how JSON objects are mapped.

Finally, since the result of refresh operations often doesn't include data provided in the initial token exchange request (such as device_secret), the process for merging tokens during refresh operations has been moved to a protocol. This is not yet public, but this may be exposed in the future.

This PR:

  1. Alters Token to conform to HasClaims so its raw JSON token response data is stored and persisted
  2. Defines properties defined by the OAuth2 specs, including required values (such as Token Type, Access Token, etc)
  3. Includes version migration support to handle loading and parsing of tokens stored with previous versions of the SDK
  4. Refines and makes the HasClaims value functions work consistently (since there were gaps before)
  5. Cleans up JSON handling, as well as documentation updates