Skip to content

Instantly share code, notes, and snippets.

@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;
@staltz
staltz / introrx.md
Last active May 10, 2024 12:08
The introduction to Reactive Programming you've been missing