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

undefined credentials is generated for an OpenAPI file which has no authentication required #2005

Closed
zaakn opened this issue Sep 5, 2023 · 3 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@zaakn
Copy link

zaakn commented Sep 5, 2023

autorest version

$ autorest --version
AutoRest code generation utility [cli version: 3.6.3; node: v18.17.1]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest


Showing All Installed Extensions

 Type       Extension Name                           Version      Location 
 core       @autorest/core                           3.9.7        /Users/fai/.autorest/@autorest_core@3.9.7
 extension  @autorest/modelerfour                    4.26.2       /Users/fai/.autorest/@autorest_modelerfour@4.26.2
 extension  @autorest/typescript                     6.0.8        /Users/fai/.autorest/@autorest_typescript@6.0.8

generate code

openapi file: pets.json which has no authentication required.

$ autorest --typescript --input-file=pets.json 
success
AutoRest code generation utility [cli version: 3.6.3; node: v18.17.1]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
info    | AutoRest core version selected from configuration: ^3.7.0.
info    |    Loading AutoRest core      '/Users/fai/.autorest/@autorestcore@3.9.7/nodemodules/@autorest/core/dist' (3.9.7)
info    |    Loading AutoRest extension '@autorest/typescript' (latest->6.0.8)
info    |    Loading AutoRest extension '@autorest/modelerfour' (4.26.2->4.26.2)
warning | PreCheck/CheckDuplicateSchemas | Checking for duplicate schemas, this could take a (long) while.  Run with --verbose for more detail.
info    | Autorest.Typescript took 464ms
info    | Autorest completed in 6.16s. 10 files generated.

output

generated/src/petClient.ts

 24   constructor(options?: PetClientOptionalParams) {
...
 67       this.pipeline.addPolicy(
 68         coreRestPipeline.bearerTokenAuthenticationPolicy({
 69           credential: credentials,
 70           scopes:
 71             optionsWithDefaults.credentialScopes ??
 72             `${optionsWithDefaults.endpoint}/.default`,
 73           challengeCallbacks: {
 74             authorizeRequestOnChallenge:
 75               coreClient.authorizeRequestOnClaimChallenge
 76           }
 77         })
 78       );

The undefined credentials appears unexpectedly (line 69)

init client

To avoid some execution errors, just make up a meaningless Pipeline.

const newPetClient = () => {
  const pipeline = coreRestPipeline.createEmptyPipeline()
  pipeline.addPolicy({
    name: coreRestPipeline.bearerTokenAuthenticationPolicyName,
    sendRequest: (request, next) => {
      // ...
      return next(request)
    },
  })

  const client = new PetClient({
    pipeline: pipeline,
    // ...
  })

  return client
}

see also:

this.pipeline.addPolicy(
coreRestPipeline.bearerTokenAuthenticationPolicy({
credential: credentials,
scopes: optionsWithDefaults.credentialScopes??\`$\{optionsWithDefaults.endpoint}/.default\`,
challengeCallbacks: {
authorizeRequestOnChallenge:
coreClient.authorizeRequestOnClaimChallenge
}
})

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Sep 5, 2023
@MaryGao
Copy link
Contributor

MaryGao commented Sep 8, 2023

@zaakn Thanks for reporting this! I believe this issue is resolved in our latest pr. We will release this in recent days and will keep you updated!

@MaryGao
Copy link
Contributor

MaryGao commented Sep 12, 2023

@zaakn Could you try with the latest version to check if this is resolved?
https://www.npmjs.com/package/@autorest/typescript?activeTab=versions

@MaryGao MaryGao added the needs-author-feedback More information is needed from author to address the issue. label Sep 12, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the no-recent-activity There has been no recent activity on this issue. label Sep 20, 2023
@microsoft-github-policy-service
Copy link
Contributor

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants