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

Request Context With Middleware Options #367

Merged
merged 13 commits into from
Feb 15, 2019
Merged

Conversation

peombwa
Copy link
Member

@peombwa peombwa commented Jan 24, 2019

Fixes issue #362

Changes proposed in this pull request

Adds middleware options

Customers can pass configuration options to middleware handlers using a set of pre-configured IBaseRequest extension methods to alter the handlers behaviour per request.

HttpProvider httpProvider = new HttpProvider();

var graphClient = new GraphServiceClient(appOnlyProvider, httpProvider);
graphClient.PerRequestAuthProvider = () => CreateDelegatedProvider();

var me = await graphClient.Me.Request()
.WithScopes(string [] { "User.Read" }) // adds auth scopes & is defined by the auth provider
.WithMaxRetry(5) // specifies maximum number of retries & is defined by the auth provider
.WithPerRequestAuthProvider() // configures the per request auth provider for this single request
.GetAsync();

Adds ability to set feature flags to http client's default headers

this.httpClient.SetFeatureFlags(FeatureFlag.RedirectHandler | FeatureFlag.RetryHandler | FeatureFlag.AuthHandler | FeatureFlag.DefaultHttpProvider);

Adds IAuthProviderOption interface

The IAuthProviderOption will be used by the auth providers to set provider specific options as part of the request.
The auth providers will expose and extension method to IBaseRequest which sets the options it needs e.g.

.WithScopes(scopes)
.WithUser(UserAccount)

Adds a RequestContext object that's set on HttpRequestMessage property bag with every request

The request context contains :

  • Middleware options map
  • Client request id
  • Cancelation Token
  • FeatureUsage flags

Other links

@peombwa peombwa changed the title Middlewareoptions Request Context With Middleware Options Jan 24, 2019
Copy link
Contributor

@MIchaelMainer MIchaelMainer left a comment

Choose a reason for hiding this comment

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

Two changes:

  • Change FeatureFlgs to enum flags
  • Make sure that customer set ClientRequestId always win regardless of when it is set (see comments)/

@darrelmiller
Copy link
Contributor

Using .WithAuthProvider(delegateOnlyProvider) is good if you are in an environment where you have access to the AuthProvider instance. However, in a WebApp controller you may not want to add the complexity of injecting in the AuthProvider instance into the controller.

Would it make sense to do something like this?

HttpProvider httpProvider = new HttpProvider();

var graphClient = new GraphServiceClient(appOnlyProvider, httpProvider);
graphClient.PerRequestAuthProvider = () => CreateDelegatedProvider();

var me = await graphClient.Me.Request()
.WithScopes(string [] { "User.Read" }) // adds auth scopes
.WithMaxRetry(5) // specifies maximum number of retries
.WithPerRequestAuthProvider()
.GetAsync();

This would allow the graphClient instance to be created in Startup, configured and the .WithPerRequestAuthProvider() can get the instance of the AuthProvider.

MIchaelMainer
MIchaelMainer previously approved these changes Feb 15, 2019
@MIchaelMainer MIchaelMainer merged commit cd8f557 into dev Feb 15, 2019
@Misiu
Copy link

Misiu commented Apr 8, 2019

I'm aware that this is an old issue, but for someone like me, everything related to MS Graph is new.
I'm trying to use Graph in Windows Service to send mail.
Because this repo is for bugs and feature requests I've created a question on SO: https://stackoverflow.com/questions/55571720/correct-way-to-create-confidentialclientapplication-that-allows-retry-for-window.
I'll be grateful if You guys could take a look.

Currently this repo don't have any examples provided. Can we ask for creating them (can we create issues for that)?

@michael-hawker
Copy link
Contributor

@peombwa looks like WithScopes wasn't implemented though it's in all the examples here? Was this an oversight or should a new issue be filed?

@darrelmiller
Copy link
Contributor

For anyone else looking, it is over here https://github.com/microsoftgraph/msgraph-sdk-dotnet-auth/blob/ae832dfc319f1fa06732cf0e7cadc133ddefbd93/src/Microsoft.Graph.Auth/Extensions/BaseRequestExtensions.cs

@peombwa peombwa deleted the middlewareoptions branch June 29, 2023 15:55
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.

None yet

5 participants