Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable authentication middleware #28

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

kostrse
Copy link
Collaborator

@kostrse kostrse commented Jan 18, 2023

The signature of azhttpclient.AzureMiddleware was changed to support configuration via the azhttpclient.AuthOptions options bag. This gives flexibility of introducing new (optional) configuration options and features into the middleware without having to change the function signatures.

One added feature is ability to register custom token providers for custom credential types, other than known by the SDK.

// Initialize the options
authOpts := azhttpclient.NewAuthOptions(azureSettings)

// Configure instance-level scopes
authOpts.Scopes(new []string {"https://datasource.example.org/.default"})

// Optionally, register custom token providers
authOpts.AddTokenProvider("custom-auth-type, func (...) (aztokenprovider.AzureTokenProvider, error) {
})

// Configure client
clientOpts := httpclient.Options{}
azhttpclient.AddAzureAuthentication(&clientOpts, authOpts, credentials)

httpClient, err := httpclient.NewProvider().New(clientOpts)

Fixes #16

azhttpclient/middleware.go Show resolved Hide resolved
azhttpclient/options.go Show resolved Hide resolved
@aangelisc
Copy link
Contributor

Once you're ready to change the status of this PR @kostrse then it should be ready for approval. My only request is to update the CHANGELOG to make a note of the breaking change. I realise we haven't been tracking releases properly but we can retrospectively update this.

@kostrse kostrse marked this pull request as ready for review January 28, 2023 02:40
@kostrse kostrse requested a review from a team as a code owner January 28, 2023 02:40
Copy link
Contributor

@aangelisc aangelisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this @kostrse 😊

@kostrse kostrse merged commit 017404c into grafana:main Jan 31, 2023
@kostrse kostrse deleted the configurable-middleware branch January 31, 2023 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable Azure authentication middleware for support of custom token providers
3 participants