What is @azure/core-auth?
The @azure/core-auth package provides a standard way to manage authentication and authorization across the Azure SDKs in JavaScript. It includes a set of interfaces and classes that can be used to implement authentication mechanisms such as token credentials, and to integrate with various Azure services that require authentication.
What are @azure/core-auth's main functionalities?
TokenCredential Interface
The TokenCredential interface is a core component that allows for the implementation of custom authentication mechanisms. When you implement this interface, you can use it with Azure SDKs that accept credential objects for authentication. The code sample demonstrates how to create a custom credential class that extends TokenCredential.
class MyCredential extends TokenCredential {
async getToken(scopes, options) {
// Your logic to acquire a token
return { token: 'your_token', expiresOnTimestamp: 12345 };
}
}
DefaultAzureCredential
DefaultAzureCredential is a class that provides a seamless authentication experience across Azure services. It tries multiple credentials in a specific order, attempting to find the best one that works for the current environment. This code sample shows how to instantiate DefaultAzureCredential, which can then be passed to other Azure SDK clients for authentication.
const { DefaultAzureCredential } = require('@azure/identity');
const credential = new DefaultAzureCredential();
Other packages similar to @azure/core-auth
aws-sdk
The AWS SDK for JavaScript provides a similar set of functionalities for AWS services as @azure/core-auth does for Azure. It includes mechanisms for authenticating against AWS services. However, it is specifically tailored for AWS and not directly compatible with Azure services.
google-auth-library
This library offers authentication and authorization utilities for Google Cloud services. Similar to @azure/core-auth, it provides a way to obtain credentials and authenticate API requests. The main difference lies in the ecosystem it targets, focusing on Google Cloud instead of Azure.
Azure Core Authentication
This library provides core interfaces and helper methods for authenticating with Azure services using Azure Active Directory and other authentication schemes common across the Azure SDK. As a "core" library, it shouldn't need to be added as a dependency to any user code, only other Azure SDK libraries.
Contributing
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.