This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 597
Improve extensibility of middleware by introducing interfaces for AuthenticationOptions #44
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/Microsoft.AspNet.Security.Facebook/IFacebookAuthenticationOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNet.Http.Security; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.AspNet.Security.Facebook | ||
{ | ||
/// <summary> | ||
/// Summary description for IFacebookAuthenticationOptions | ||
/// </summary> | ||
public interface IFacebookAuthenticationOptions : IAuthenticationOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Facebook-assigned appId | ||
/// </summary> | ||
string AppId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Facebook-assigned app secret | ||
/// </summary> | ||
string AppSecret { get; set; } | ||
#if NET45 | ||
/// <summary> | ||
/// Gets or sets the a pinned certificate validator to use to validate the endpoints used | ||
/// in back channel communications belong to Facebook. | ||
/// </summary> | ||
/// <value> | ||
/// The pinned certificate validator. | ||
/// </value> | ||
/// <remarks>If this property is null then the default certificate checks are performed, | ||
/// validating the subject name and if the signing chain is a trusted party.</remarks> | ||
ICertificateValidator BackchannelCertificateValidator { get; set; } | ||
#endif | ||
/// <summary> | ||
/// Gets or sets timeout value in milliseconds for back channel communications with Facebook. | ||
/// </summary> | ||
/// <value> | ||
/// The back channel timeout in milliseconds. | ||
/// </value> | ||
TimeSpan BackchannelTimeout { get; set; } | ||
|
||
/// <summary> | ||
/// The HttpMessageHandler used to communicate with Facebook. | ||
/// This cannot be set at the same time as BackchannelCertificateValidator unless the value | ||
/// can be downcast to a WebRequestHandler. | ||
/// </summary> | ||
HttpMessageHandler BackchannelHttpHandler { get; set; } | ||
|
||
/// <summary> | ||
/// Get or sets the text that the user can display on a sign in user interface. | ||
/// </summary> | ||
string Caption { get; set; } | ||
|
||
/// <summary> | ||
/// The request path within the application's base path where the user-agent will be returned. | ||
/// The middleware will process this request when it arrives. | ||
/// Default value is "/signin-facebook". | ||
/// </summary> | ||
PathString CallbackPath { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user <see cref="System.Security.Claims.ClaimsIdentity"/>. | ||
/// </summary> | ||
string SignInAsAuthenticationType { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="IFacebookAuthenticationNotifications"/> used to handle authentication events. | ||
/// </summary> | ||
IFacebookAuthenticationNotifications Notifications { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the type used to secure data handled by the middleware. | ||
/// </summary> | ||
ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; } | ||
|
||
/// <summary> | ||
/// A list of permissions to request. | ||
/// </summary> | ||
IList<string> Scope { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets if the appsecret_proof should be generated and sent with Facebook API calls. | ||
/// This is enabled by default. | ||
/// </summary> | ||
bool SendAppSecretProof { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.AspNet.Http.Security; | ||
|
||
namespace Microsoft.AspNet.Security | ||
{ | ||
/// <summary> | ||
/// Interface for Base Options for all authentication middleware | ||
/// </summary> | ||
public interface IAuthenticationOptions | ||
{ | ||
/// <summary> | ||
/// The AuthenticationType in the options corresponds to the IIdentity AuthenticationType property. A different | ||
/// value may be assigned in order to use the same authentication middleware type more than once in a pipeline. | ||
/// </summary> | ||
string AuthenticationType { get;set; } | ||
|
||
/// <summary> | ||
/// If Active the authentication middleware alter the request user coming in and | ||
/// alter 401 Unauthorized responses going out. If Passive the authentication middleware will only provide | ||
/// identity and alter responses when explicitly indicated by the AuthenticationType. | ||
/// </summary> | ||
AuthenticationMode AuthenticationMode { get; set; } | ||
|
||
/// <summary> | ||
/// Additional information about the authentication type which is made available to the application. | ||
/// </summary> | ||
AuthenticationDescription Description { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the multi-tenant scenario how does the options implementer get access to the current request in order to decide which AppId to return? HttpContext.Current? That's not a pattern we want to encourage. They'd also have to re-execute that discovery logic for every property call (AppId, AppSecret, Scope, etc.).
Would you do anything differently if you weren't concerned about back-compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! In my working example (the one where I duplicated the Facebook middleware) I use HttpContext.Current to get the current Owin context in which I've already built up a TenantContext with other middleware.
Is there a better way to get access to the context?
If not concerned about backward compatibility I might add a factory method to IAuthenticationOptions, perhaps BuildOptionsForRequest(HttpRequest request). We might call that method from the AuthenticationHandler as part of the per-request work performed. Honestly I haven't thought that through completely but that's probably the direction I'd head in. Do you think that's a better design? Personally I think HttpContext.Current is a fine way for auth middleware to get the context but perhaps I'm not seeing the whole picture.
Side note, I think there is a slight bias towards these AuthenticationOptions being static in nature (set once and forget), which probably makes sense for a lot of developers in simple scenarios, but add in even modestly complex requirements and that design breaks down quickly. I think the bias should be towards per-request configuration -- after all, we're looking at every request already -- and then the default AuthenticationOptions implementation can just support a static configuration for the majority of "basic" users to roll out of the box.
Thanks for your thoughts on this, cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more info:
In my current hacked version (on top of Owin.Security) I initialize FacebookAuthenticationOptions with a "settings provider" which uses a cache of tenant contexts and the current request to resolve facebook api settings per tenant.
So the FacebookAuthenticationOptions class looks like this (abbreviated):
And the provider: