An NPM module to use with azure related actions to help communicate with Azure API
// javascript
const core = require('@azure-actions/auth');
// typescript
import * as core from '@azure-actions/auth';
There are two scenarios in which you could use this.
- Get Access token within
az login
context.
let token = getAzureAccessToken();
- Passing the SPN creds inline as a string in JSON.
let credentials = core.getInput('azure-credentials'); // SPN creds input
let token = getAzureAccessToken(credentials);
To fetch the credentials required to authenticate with Azure, run the following command:
az ad sp create-for-rbac --sdk-auth
For more details on this command, refer to service principal documentation
This generates a service principal and the output of the above command will be in the following format:
{
"clientId": "<client id>",
"clientSecret": "<client secret>",
"subscriptionId": "<subscription id>",
"tenantId": "<tenant id>",
"activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
"resourceManagerEndpointUrl": "https://management.azure.com/",
"activeDirectoryGraphResourceId": "https://graph.windows.net/",
"sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
"galleryEndpointUrl": "https://gallery.azure.com/",
"managementEndpointUrl": "https://management.core.windows.net/"
}