我使用autorest来生成用于访问RESTful web服务的TypeScript客户端。所有REST都在寻找用于身份验证的承载令牌,但我没有找到将令牌传递给自动生成的TypeScript客户端的方法。
我确实尝试过搜索自动休息文档。看起来我需要使用ServiceClientCredentials,但我没有找到任何示例代码。
有人知道如何在ServiceClientCredentials中使用TypeScript吗?
我使用以下命令生成TypeScript客户端
autorest --input-file=restapi.json --typescript --output-folder=./output --package-name="test-api" --package-version="0.1.0" --generate-metadata=true --add-credentials=true发布于 2018-09-04 01:53:25
我找到了答案。我需要创建一个TokenCredentials对象,并将它传递到自动生成的客户机中。
// Create token
const tokenCredentials: TokenCredentials = new TokenCredentials(
'some token'
);
// Add token and server url to service instance
const service: AutoGeneratedSvc = new AutoGeneratedSvc(
tokenCredentials,
'server url'
);https://stackoverflow.com/questions/52142970
复制相似问题