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

[core-http] Should TokenCredential.getToken accept a more granular type than RequestOptionsBase? #3535

Closed
daviwil opened this issue Jun 6, 2019 · 7 comments · Fixed by #3681

Comments

@daviwil
Copy link
Contributor

daviwil commented Jun 6, 2019

This issue tracks a PR discussion which asks whether we should create a more granular type in @azure/core-http than RequestOptionsBase to pass to TokenCredential.getToken.

The easiest option is to just re-export this type from @azure/identity. Even if we make a more narrowly-scoped type for getToken to use, it'd still have to live in @azure/core-http to be used in the TokenCredential interface. RequestOptionsBase is pretty minimal and only refers to one other type (TransferProgressEvent), so it doesn't bring along any major baggage. The properties that it does contain are fairly useful for the purpose of augmenting HTTP requests that are sent through the pipeline.

/cc @schaabs @ramya-rao-a @bterlson

@schaabs
Copy link
Member

schaabs commented Jun 7, 2019

Exporting this from @azure/identity doesn't solve the problem. No client libraries should take a dependency on @azure/identity

@schaabs
Copy link
Member

schaabs commented Jun 7, 2019

I think the solution to this is to have it take it's own type of option bag, something like GetTokenOptions. Then in @azure/identity implementation define a new interface which is both GetTokenOptions and RequestOptionsBase, something like IdentityRequestOptions. Thoughts?

@ramya-rao-a
Copy link
Contributor

Is GetTokenOptions in your proposal a function or a type?

Are we saying

getToken(scopes: string | string[], requestOptions?: RequestOptionsBase)

becomes

getToken(scopes: string | string[], tokenOptions?: any)

in TokenCredential

and in Azure Identity, all implementations will use

getToken(scopes: string | string[], tokenOptions?: RequestOptionsBase) ?

@daviwil
Copy link
Contributor Author

daviwil commented Jun 7, 2019

Apologies, I didn't fill in the gap as to why the "export from @azure/identity" suggestion was the solution.

Here are the facts:

  • We don't want end users to depend on @azure/core-http directly
  • @azure/identity exports TokenCredential implementations that will be created and passed to SDK client libraries like @azure/keyvault-keys
  • TokenCredential.getToken takes a RequestOptionsBase so that any HTTP requests created in that call can be configured and an aborter can be passed through
  • The end user shouldn't need to call TokenCredential.getToken, but since TokenCredential implementations have a public getToken method, it makes sense to re-export the RequestOptionsBase interface through @azure/identity so that they don't have "missing type" issues

But maybe the idea behind this issue is moot: The only code that consumes TokenCredentials is @azure/core-http and since TokenCredential is an interface, the TypeScript compiler should accept an implementation of it even if the end user doesn't have direct access to the TokenCredential interface. That would make RequestOptionsBase (and TokenCredential) an internal implementation detail between @azure/identity and @azure/core-http which doesn't need to be exposed to the end user.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jun 7, 2019

The only code that consumes TokenCredentials is @azure/core-http

That is not true. Non http client libraries like Event Hubs and Service Hubs will need to run the getToken() function to get the token and pass it to the service for auth

And these libraries do not care about the requestOptionsBase

@daviwil
Copy link
Contributor Author

daviwil commented Jun 7, 2019

Good point, I suppose if they implemented some concept of a "policy" it'd be outside of @azure/core-http since they don't use HTTP as their own transport.

RequestOptionsBase is still relevant for requesting the token though since that request is done over HTTP against the AAD service.

@schaabs
Copy link
Member

schaabs commented Jun 7, 2019

As we discussed offline this should be just the aborter or possibly separate options class which for now just contains the aborter for now.

daviwil added a commit to daviwil/azure-sdk-for-js that referenced this issue Jun 12, 2019
This change draws on work done by schaabs in
Azure/azure-sdk-for-net#6525 to refactor Azure.Core and Azure.Identity
to respond to architecture board feedback.  It also makes a couple of
TypeScript-specific tweaks that were discussed at the time
@azure/identity was introduced.

Fixes Azure#3535.
Fixes Azure#3529.
daviwil added a commit that referenced this issue Jun 12, 2019
…back (#3681)

This change draws on work done by schaabs in
Azure/azure-sdk-for-net#6525 to refactor Azure.Core and Azure.Identity
to respond to architecture board feedback.  It also makes a couple of
TypeScript-specific tweaks that were discussed at the time
@azure/identity was introduced.

Fixes #3535.
Fixes #3529.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants