Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a customProvider option to the sdk JwtBearerAuth class #5105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mathieuartu
Copy link
Contributor

@mathieuartu mathieuartu commented Jan 7, 2025

Explanation

This PR adds the possibility to use a customProvider for the JwtBearerAuth class.
This is added both as a constructor option, and as a method to set the custom provider as a later point in time, using the setCustomProvider method.

References

Changelog

@metamask/profile-sync-controller

  • ADDED: customProvider option for the sdk JwtBearerAuth class

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mathieuartu mathieuartu added the team-identity Identity Team changes. https://github.com/orgs/MetaMask/teams/identity label Jan 7, 2025
@mathieuartu mathieuartu self-assigned this Jan 7, 2025
@mathieuartu mathieuartu changed the title feat: add customProvider option to the sdk auth class feat: add a customProvider option to the sdk JwtBearerAuth class Jan 7, 2025
Copy link
Contributor

@dovydas55 dovydas55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mathieuartu
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented Jan 7, 2025

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.2-preview-cdca062",
  "@metamask-previews/address-book-controller": "6.0.2-preview-cdca062",
  "@metamask-previews/announcement-controller": "7.0.2-preview-cdca062",
  "@metamask-previews/approval-controller": "7.1.1-preview-cdca062",
  "@metamask-previews/assets-controllers": "45.1.2-preview-cdca062",
  "@metamask-previews/base-controller": "7.1.0-preview-cdca062",
  "@metamask-previews/build-utils": "3.0.2-preview-cdca062",
  "@metamask-previews/chain-controller": "0.2.2-preview-cdca062",
  "@metamask-previews/composable-controller": "10.0.0-preview-cdca062",
  "@metamask-previews/controller-utils": "11.4.4-preview-cdca062",
  "@metamask-previews/ens-controller": "15.0.1-preview-cdca062",
  "@metamask-previews/eth-json-rpc-provider": "4.1.7-preview-cdca062",
  "@metamask-previews/gas-fee-controller": "22.0.2-preview-cdca062",
  "@metamask-previews/json-rpc-engine": "10.0.2-preview-cdca062",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.6-preview-cdca062",
  "@metamask-previews/keyring-controller": "19.0.2-preview-cdca062",
  "@metamask-previews/logging-controller": "6.0.3-preview-cdca062",
  "@metamask-previews/message-manager": "11.0.3-preview-cdca062",
  "@metamask-previews/multichain": "2.0.0-preview-cdca062",
  "@metamask-previews/name-controller": "8.0.2-preview-cdca062",
  "@metamask-previews/network-controller": "22.1.1-preview-cdca062",
  "@metamask-previews/notification-services-controller": "0.15.0-preview-cdca062",
  "@metamask-previews/permission-controller": "11.0.4-preview-cdca062",
  "@metamask-previews/permission-log-controller": "3.0.2-preview-cdca062",
  "@metamask-previews/phishing-controller": "12.3.1-preview-cdca062",
  "@metamask-previews/polling-controller": "12.0.2-preview-cdca062",
  "@metamask-previews/preferences-controller": "15.0.1-preview-cdca062",
  "@metamask-previews/profile-sync-controller": "3.1.1-preview-cdca062",
  "@metamask-previews/queued-request-controller": "8.0.2-preview-cdca062",
  "@metamask-previews/rate-limit-controller": "6.0.2-preview-cdca062",
  "@metamask-previews/remote-feature-flag-controller": "1.2.0-preview-cdca062",
  "@metamask-previews/selected-network-controller": "20.0.2-preview-cdca062",
  "@metamask-previews/signature-controller": "23.2.0-preview-cdca062",
  "@metamask-previews/transaction-controller": "42.1.0-preview-cdca062",
  "@metamask-previews/user-operation-controller": "21.0.0-preview-cdca062"
}

@mathieuartu mathieuartu marked this pull request as ready for review January 7, 2025 10:17
@mathieuartu mathieuartu requested review from a team as code owners January 7, 2025 10:17
@@ -44,6 +46,11 @@ export class JwtBearerAuth implements SIWEInterface, SRPInterface {
throw new UnsupportedAuthTypeError('unsupported auth type');
}

setCustomProvider(provider: Eip1193Provider) {
this.#assertSRP(this.#type, this.#sdk);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Yeah we only need this for the SRP flow for now 🙂

@@ -143,6 +143,28 @@ describe('Authentication - constructor()', () => {
);
}).toThrow(UnsupportedAuthTypeError);
});

it('supports using a custom provider as a constructor option', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-identity Identity Team changes. https://github.com/orgs/MetaMask/teams/identity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants