Autorest only supports 2 types of authentication, any other will need to be handled manually:
oauth2: Represent an OAuth2 authenticationapiKeywithin: header: Represent an api key authentication sent via header
This can be either configured in OpenAPI spec or using flags/config
This uses OpenAPI security model
- OpenAPI 3
{
"components": {
"securitySchemes": {
"AADToken": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/authorize",
"tokenUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/token"
}
}
}
}
},
"security": [
{
"AADToken": ["https://myservice.azure.com/.default"]
}
]
}- Swagger 2.0
{
"securityDefinitions": {
"AADToken": {
"type": "oauth2",
"flow": "accessCode",
"authorizationUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/authorize",
"tokenUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/token"
}
},
"security": [
{
"AADToken": ["https://myservice.azure.com/.default"]
}
]
}Alternatively instead of using a $ref you can
- OpenAPI 3
{
"components": {
"securitySchemes": {
"AzureKey": {
"type": "apiKey",
"in": "header",
"name": "my-header-name"
}
}
},
"security": [
{
"AzureKey": []
}
]
}- Swagger 2.0
{
"securityDefinitions": {
"AzureKey": {
"type": "apiKey",
"in": "header",
"name": "my-header-name"
}
},
"security": [
{
"AzureKey": []
}
]
}There is a few config options that will result in the same generation:
This is a list of the supported security schemes(AADToken | AzureKey).
Example
# For AAD Token only
security: AADToken
# For Azure key only
security: AzureKey
# For both
security: [AADToken, AzureKey]By default:
AADTokenscope ishttps://management.azure.com/.defaultAzureKeyheader name isAuthorization
To be used with security: AADToken will override the list of scopes.
Example:
security: AADToken
security-scopes:
- "https://fakeendpoint.azure.com/.default"
- "https://dummyendpoint.azure.com/.default"To be used with security: AzureKey will override the header name.
Example:
security: AzureKey
security-header-name: CustomAuthThis will automatically configure AADToken credentials with https://management.azure.com/.default scope.
Equivalent to passing
{
"components": {
"securitySchemes": {
"AADToken": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/authorize",
"tokenUrl": "https://login.microsoftonline.com/common/v2.0/oauth2/token"
}
}
}
}
},
"security": [{ "AADToken": ["https://management.azure.com/.default"] }]
}