Skip to content

Instantly share code, notes, and snippets.

View schaabs's full-sized avatar

Scott Schaab schaabs

View GitHub Profile
@schaabs
schaabs / custom-credential-preview.md
Last active September 22, 2021 11:57
Defining Custom Credential Types

Authenticating with a prefetched access token

The Azure.Identity library does not contain a TokenCredential implementation which can be constructed directly with an AccessToken. This is intentionally omitted as authenticating a client with a static token is in most cases an anti-pattern, as access tokens expire frequently and have constrained usage. However, there are some scenarios where authenticating a service client with a prefetched token is necessary.

In this example StaticTokenCredential implements the TokenCredential abstraction. It takes a prefetched access token in its constructor as a string or AccessToken, and simply returns that from its implementation of GetToken and GetTokenAsync.

public class StaticTokenCredential : TokenCredential
{
    private AccessToken _token;

Authenticating Clients to the Key Vault

Azure Key Vault authenticates requests via Azure Active Directory OAuth access tokens. All clients in the azure-keyvault package require an instance of the TokenCredential interface. The TokenCredential interface is located in the azure-common package.

While some applications with special requirements may choose to provide a TokenCredential implementation of their own, most can utilize the implementations provided by the Azure Identity library.

Authenticating Using the Azure Identity Library

To use the Azure Identity Library for authenticating client requests, you must first reference the azure-identity package in your project. The following reference should be added to the project pom.xml dependencies section:

@schaabs
schaabs / secret_refactor.ts
Created April 7, 2019 07:49
Secret interface refactoring
export interface Secret extends SecretAttributes
{
/**
* @member {string} [value] The secret value.
*/
value?: string;
}
export interface SecretAttributes extends ParsedKeyVaultEntityIdentifier {
/**