logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
7.79k stars 383 forks source link

feat(core): actor token #6171

Open wangsijie opened 4 days ago

wangsijie commented 4 days ago

Summary

Implement "actor token" feature in token exchange according to the RFC.

If actor_token is present, will add an extra claim act to the response access token.

Because the class AccessToken can only accept a list of predefined claims, so we have to set the act claim to extra first, and then extract it to the outside in extraTokenClaims option of node-oidc-provider.

This PR also includes the refactor of token-exchange.ts, it is now splited into a folder of files.

Testing

Unit and integration tests.

Checklist

github-actions[bot] commented 4 days ago

COMPARE TO master

Total Size Diff :warning: :chart_with_upwards_trend: +10.68 KB

Diff by File |Name|Diff| |---|---| |packages/core/src/oidc/extra-token-claims.ts|:chart_with_upwards_trend: +900 Bytes| |packages/core/src/oidc/grants/index.ts|:chart_with_upwards_trend: +6 Bytes| |packages/core/src/oidc/grants/token-exchange.test.ts|:chart_with_upwards_trend: +8.79 KB| |packages/core/src/oidc/grants/token-exchange.ts|:chart_with_upwards_trend: +8.17 KB| |packages/core/src/oidc/grants/token-exchange/actor-token.test.ts|:chart_with_upwards_trend: +1.82 KB| |packages/core/src/oidc/grants/token-exchange/actor-token.ts|:chart_with_upwards_trend: +1.39 KB| |packages/core/src/oidc/grants/token-exchange/index.test.ts|:chart_with_upwards_trend: +9.07 KB| |packages/core/src/oidc/grants/token-exchange/index.ts|:chart_with_upwards_trend: +8.93 KB| |packages/core/src/oidc/grants/token-exchange/types.ts|:chart_with_upwards_trend: +299 Bytes| |packages/core/src/oidc/init.ts|:chart_with_upwards_trend: +211 Bytes| |packages/integration-tests/src/tests/api/oidc/token-exchange.test.ts|:chart_with_upwards_trend: +5.04 KB|