Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
142 stars 166 forks source link

Add a way to configure Authorization Scopes at runtime in the generated SDK #3432

Open satumkurmsft opened 1 year ago

satumkurmsft commented 1 year ago

Describe the issue or request We cannot override or add more scopes to the SDK. It would be great to have a way to do this

We have the following declaration to allow Apikey and Token based auth

@useAuth(
  ApiKeyAuth<ApiKeyLocation.header, "api-key"> |
  OAuth2Auth<[{
    type: OAuth2FlowType.implicit,
    authorizationUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
    scopes: ["https://cognitivesearch.azure.com/.default"]
  }]>
)

In the generated C# SDK, this seems to be hard-coding the authorizationScope value when it creates BearerTokenAuthenticationPolicy. But we have a unique situation where in dev environment, we support another scope and want to use that to get tokens.

cronologi commented 1 year ago

I would be interested in that as well. How is the user of the generated SDK supposed to override the scopes and set them dynamically to support switching from one Application URI to another; for example to either target the DEV instance of the REST API or the PROD instance (if two separate App Registrations exist)?

chunyu3 commented 11 months ago

Need typespec to define how to define a scope parameter which can updated, not a constant tuple.