From a83da598165339a7b2bce932e7d593f7330a4fd3 Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Thu, 19 Mar 2015 14:51:44 +0000 Subject: [PATCH 1/6] - Removed scope; - Added comments; --- .../FoursquareAuthenticationHandler.cs | 6 +- .../FoursquareAuthenticationMiddleware.cs | 8 ++ .../FoursquareAuthenticationOptions.cs | 6 -- .../FoursquareAuthenticatedContext.cs | 85 +++++++++++++++++++ .../FoursquareAuthenticationProvider.cs | 22 +++++ .../FoursquareReturnEndpointContext.cs | 3 + .../IFoursquareAuthenticationProvider.cs | 13 +++ 7 files changed, 132 insertions(+), 11 deletions(-) diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs index 8979ac6..b17631c 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs @@ -174,17 +174,13 @@ namespace Owin.Security.Providers.Foursquare // OAuth2 10.12 CSRF this.GenerateCorrelationId(extra); - // OAuth2 3.3 space separated - var scope = string.Join(" ", this.Options.Scope); - var state = this.Options.StateDataFormat.Protect(extra); var authorizationEndpoint = AuthorizationEndpoint + "?client_id=" + Uri.EscapeDataString(this.Options.ClientId) + "&response_type=code" + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + - "&state=" + Uri.EscapeDataString(state) + - "&scope=" + Uri.EscapeDataString(scope); + "&state=" + Uri.EscapeDataString(state); this.Response.Redirect(authorizationEndpoint); } diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs index 6980598..f12f0d5 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs @@ -51,6 +51,14 @@ namespace Owin.Security.Providers.Foursquare this._httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB } + /// + /// Provides the object for processing + /// authentication-related requests. + /// + /// + /// An configured with the + /// supplied to the constructor. + /// protected override AuthenticationHandler CreateHandler() { return new FoursquareAuthenticationHandler(this._httpClient, this._logger); diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs index defcec3..e1356d2 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs @@ -18,7 +18,6 @@ namespace Owin.Security.Providers.Foursquare this.CallbackPath = "/signin-foursquare"; this.AuthenticationMode = AuthenticationMode.Passive; this.BackchannelTimeout = TimeSpan.FromSeconds(60); - this.Scope = new List(); } /// @@ -82,11 +81,6 @@ namespace Owin.Security.Providers.Foursquare /// public ISecureDataFormat StateDataFormat { get; set; } - /// - /// A list of permissions to request. - /// - public IList Scope { get; private set; } - /// /// Get or sets the text that the user can display on a sign in user interface. /// diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs index d85da87..d7a5ae1 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs @@ -7,8 +7,17 @@ using Newtonsoft.Json.Linq; namespace Owin.Security.Providers.Foursquare.Provider { + /// + /// Contains information about the login session as well as the user . + /// public class FoursquareAuthenticatedContext : BaseContext { + /// + /// Initializes a + /// + /// The OWIN environment + /// The JSON-serialized user + /// GitHub Access token public FoursquareAuthenticatedContext(IOwinContext context, JObject user, string accessToken) : base(context) { @@ -49,29 +58,105 @@ namespace Owin.Security.Providers.Foursquare.Provider this.Link = "https://foursquare.com/user/" + this.Id; } + /// + /// Gets the JSON-serialized user + /// + /// + /// Contains the Foursquare user obtained from the User Info endpoint. By default this is https://api.foursquare.com/v2/users/self but it can be + /// overridden in the options + /// public JObject User { get; private set; } + /// + /// Gets the Foursquare access token + /// public string AccessToken { get; private set; } + /// + /// Gets the Foursquare user ID + /// public string Id { get; private set; } + /// + /// Gets the user's first name + /// public string FirstName { get; private set; } + /// + /// Gets the user's last name + /// public string LastName { get; private set; } + /// + /// Gets the user's full name + /// public string Name { get; private set; } + /// + /// Gets the user's gender + /// public string Gender { get; private set; } + /// + /// Gets the user's photo + /// public string Photo { get; private set; } + /// + /// Gets the user's friends + /// public string Friends { get; private set; } + /// + /// Gets the user's home city + /// public string HomeCity { get; private set; } + /// + /// Gets the user's biography + /// public string Bio { get; private set; } + /// + /// Gets the user's contact + /// public string Contact { get; private set; } + /// + /// Gets the user's phone + /// public string Phone { get; private set; } + /// + /// Gets the user's email + /// public string Email { get; private set; } + /// + /// Gets the user's Twitter handle + /// public string Twitter { get; private set; } + /// + /// Gets the user's Facebook id + /// public string Facebook { get; private set; } + /// + /// Gets the user's badges + /// public string Badges { get; private set; } + /// + /// Gets the user's mayorships + /// public string Mayorships { get; private set; } + /// + /// Gets the user's checkins + /// public string Checkins { get; private set; } + /// + /// Gets the user's photos + /// public string Photos { get; private set; } + /// + /// Gets the user's scores + /// public string Scores { get; private set; } + /// + /// Gets the user's link + /// public string Link { get; private set; } + /// + /// Gets the representing the user + /// public ClaimsIdentity Identity { get; set; } + /// + /// Gets or sets a property bag for common authentication properties + /// public AuthenticationProperties Properties { get; set; } private static string TryGetValue(JObject user, string propertyName) diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs index ebe5746..e1e682d 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs @@ -3,23 +3,45 @@ using System.Threading.Tasks; namespace Owin.Security.Providers.Foursquare.Provider { + /// + /// Default implementation. + /// public class FoursquareAuthenticationProvider : IFoursquareAuthenticationProvider { + /// + /// Initializes a + /// public FoursquareAuthenticationProvider() { this.OnAuthenticated = context => Task.FromResult(null); this.OnReturnEndpoint = context => Task.FromResult(null); } + /// + /// Gets or sets the function that is invoked when the Authenticated method is invoked. + /// public Func OnAuthenticated { get; set; } + /// + /// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked. + /// public Func OnReturnEndpoint { get; set; } + /// + /// Invoked whenever GitHub succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. public virtual Task Authenticated(FoursquareAuthenticatedContext context) { return this.OnAuthenticated(context); } + /// + /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. + /// + /// + /// A representing the completed operation. public virtual Task ReturnEndpoint(FoursquareReturnEndpointContext context) { return this.OnReturnEndpoint(context); diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs index 8074b4d..27fd33f 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs @@ -4,6 +4,9 @@ using Microsoft.Owin.Security.Provider; namespace Owin.Security.Providers.Foursquare.Provider { + /// + /// Provides context information to middleware providers. + /// public class FoursquareReturnEndpointContext : ReturnEndpointContext { /// diff --git a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs index 0403897..3cc8d38 100644 --- a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs @@ -2,10 +2,23 @@ namespace Owin.Security.Providers.Foursquare.Provider { + /// + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// public interface IFoursquareAuthenticationProvider { + /// + /// Invoked whenever GitHub succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. Task Authenticated(FoursquareAuthenticatedContext context); + /// + /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. + /// + /// + /// A representing the completed operation. Task ReturnEndpoint(FoursquareReturnEndpointContext context); } } \ No newline at end of file From 7b8d376846ea9585ae2b8120d2958e7327eee70d Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Thu, 19 Mar 2015 22:08:15 +0000 Subject: [PATCH 2/6] - Changed version to a fixed date; --- .../Foursquare/FoursquareAuthenticationHandler.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs index b17631c..0006af0 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs @@ -20,6 +20,8 @@ namespace Owin.Security.Providers.Foursquare private const string GraphApiEndpoint = "https://api.foursquare.com/v2/users/self"; private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; + private static readonly DateTime VersionDate = new DateTime(2015, 3, 19); + private readonly ILogger _logger; private readonly HttpClient _httpClient; @@ -103,7 +105,7 @@ namespace Owin.Security.Providers.Foursquare return new AuthenticationTicket(null, properties); } - var graphResponse = await this._httpClient.GetAsync(GraphApiEndpoint + "?oauth_token=" + Uri.EscapeDataString(accessToken) + "&m=foursquare&v=" + DateTime.Today.ToString("yyyyyMMdd"), this.Request.CallCancelled); + var graphResponse = await this._httpClient.GetAsync(GraphApiEndpoint + "?oauth_token=" + Uri.EscapeDataString(accessToken) + "&m=foursquare&v=" + VersionDate.ToString("yyyyyMMdd"), this.Request.CallCancelled); graphResponse.EnsureSuccessStatusCode(); var accountstring = await graphResponse.Content.ReadAsStringAsync(); From 5322c9310cb4075bd6d1b9abd4dcfe154acab701 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Wed, 25 Mar 2015 13:44:19 +0000 Subject: [PATCH 3/6] Corrected typo --- .../Foursquare/Provider/FoursquareAuthenticatedContext.cs | 2 +- .../Foursquare/Provider/FoursquareAuthenticationProvider.cs | 2 +- .../Foursquare/Provider/IFoursquareAuthenticationProvider.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs index d7a5ae1..be337f1 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs @@ -17,7 +17,7 @@ namespace Owin.Security.Providers.Foursquare.Provider /// /// The OWIN environment /// The JSON-serialized user - /// GitHub Access token + /// Foursquare Access token public FoursquareAuthenticatedContext(IOwinContext context, JObject user, string accessToken) : base(context) { diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs index e1e682d..8890a96 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs @@ -28,7 +28,7 @@ namespace Owin.Security.Providers.Foursquare.Provider public Func OnReturnEndpoint { get; set; } /// - /// Invoked whenever GitHub succesfully authenticates a user + /// Invoked whenever Foursquare succesfully authenticates a user /// /// Contains information about the login session as well as the user . /// A representing the completed operation. diff --git a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs index 3cc8d38..c6f79f3 100644 --- a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs @@ -8,7 +8,7 @@ namespace Owin.Security.Providers.Foursquare.Provider public interface IFoursquareAuthenticationProvider { /// - /// Invoked whenever GitHub succesfully authenticates a user + /// Invoked whenever Foursquare succesfully authenticates a user /// /// Contains information about the login session as well as the user . /// A representing the completed operation. From 5efd13c4eb088eddb77c3ea02120d6a90e352899 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Wed, 25 Mar 2015 13:45:58 +0000 Subject: [PATCH 4/6] Normalized indentation --- .../FoursquareAuthenticationHandler.cs | 316 +++++++++--------- .../FoursquareAuthenticationMiddleware.cs | 124 +++---- .../FoursquareAuthenticationOptions.cs | 148 ++++---- .../FoursquareAuthenticatedContext.cs | 302 ++++++++--------- .../FoursquareAuthenticationProvider.cs | 78 ++--- .../FoursquareReturnEndpointContext.cs | 30 +- .../IFoursquareAuthenticationProvider.cs | 34 +- 7 files changed, 516 insertions(+), 516 deletions(-) diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs index 0006af0..cfe1140 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationHandler.cs @@ -13,74 +13,74 @@ using Owin.Security.Providers.Foursquare.Provider; namespace Owin.Security.Providers.Foursquare { - public class FoursquareAuthenticationHandler : AuthenticationHandler - { - private const string AuthorizationEndpoint = "https://foursquare.com/oauth2/authenticate"; - private const string TokenEndpoint = "https://foursquare.com/oauth2/access_token"; - private const string GraphApiEndpoint = "https://api.foursquare.com/v2/users/self"; - private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; + public class FoursquareAuthenticationHandler : AuthenticationHandler + { + private const string AuthorizationEndpoint = "https://foursquare.com/oauth2/authenticate"; + private const string TokenEndpoint = "https://foursquare.com/oauth2/access_token"; + private const string GraphApiEndpoint = "https://api.foursquare.com/v2/users/self"; + private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; - private static readonly DateTime VersionDate = new DateTime(2015, 3, 19); + private static readonly DateTime VersionDate = new DateTime(2015, 3, 19); - private readonly ILogger _logger; - private readonly HttpClient _httpClient; + private readonly ILogger _logger; + private readonly HttpClient _httpClient; - public FoursquareAuthenticationHandler(HttpClient httpClient, ILogger logger) - { - this._httpClient = httpClient; - this._logger = logger; - } + public FoursquareAuthenticationHandler(HttpClient httpClient, ILogger logger) + { + this._httpClient = httpClient; + this._logger = logger; + } - public override async Task InvokeAsync() - { - if ((string.IsNullOrEmpty(this.Options.CallbackPath) == false) && (this.Options.CallbackPath == this.Request.Path.ToString())) - { - return await this.InvokeReturnPathAsync(); - } + public override async Task InvokeAsync() + { + if ((string.IsNullOrEmpty(this.Options.CallbackPath) == false) && (this.Options.CallbackPath == this.Request.Path.ToString())) + { + return await this.InvokeReturnPathAsync(); + } - return false; - } + return false; + } - protected override async Task AuthenticateCoreAsync() - { - this._logger.WriteVerbose("AuthenticateCore"); + protected override async Task AuthenticateCoreAsync() + { + this._logger.WriteVerbose("AuthenticateCore"); - AuthenticationProperties properties = null; + AuthenticationProperties properties = null; - try - { - string code = null; - string state = null; + try + { + string code = null; + string state = null; - var query = this.Request.Query; - var values = query.GetValues("code"); + var query = this.Request.Query; + var values = query.GetValues("code"); - if ((values != null) && (values.Count == 1)) - { - code = values[0]; - } + if ((values != null) && (values.Count == 1)) + { + code = values[0]; + } - values = query.GetValues("state"); + values = query.GetValues("state"); - if ((values != null) && (values.Count == 1)) - { - state = values[0]; - } + if ((values != null) && (values.Count == 1)) + { + state = values[0]; + } - properties = this.Options.StateDataFormat.Unprotect(state); + properties = this.Options.StateDataFormat.Unprotect(state); - if (properties == null) - { - return null; - } + if (properties == null) + { + return null; + } - // OAuth2 10.12 CSRF - if (this.ValidateCorrelationId(properties, this._logger) == false) - { - return new AuthenticationTicket(null, properties); - } + // OAuth2 10.12 CSRF + if (this.ValidateCorrelationId(properties, this._logger) == false) + { + return new AuthenticationTicket(null, properties); + } - var tokenRequestParameters = new List>() + var tokenRequestParameters = new List>() { new KeyValuePair("client_id", this.Options.ClientId), new KeyValuePair("client_secret", this.Options.ClientSecret), @@ -89,153 +89,153 @@ namespace Owin.Security.Providers.Foursquare new KeyValuePair("code", code), }; - var requestContent = new FormUrlEncodedContent(tokenRequestParameters); + var requestContent = new FormUrlEncodedContent(tokenRequestParameters); - var response = await this._httpClient.PostAsync(TokenEndpoint, requestContent, this.Request.CallCancelled); - response.EnsureSuccessStatusCode(); + var response = await this._httpClient.PostAsync(TokenEndpoint, requestContent, this.Request.CallCancelled); + response.EnsureSuccessStatusCode(); - var oauthTokenResponse = await response.Content.ReadAsStringAsync(); + var oauthTokenResponse = await response.Content.ReadAsStringAsync(); - var oauth2Token = JObject.Parse(oauthTokenResponse); - var accessToken = oauth2Token["access_token"].Value(); + var oauth2Token = JObject.Parse(oauthTokenResponse); + var accessToken = oauth2Token["access_token"].Value(); - if (string.IsNullOrWhiteSpace(accessToken) == true) - { - this._logger.WriteWarning("Access token was not found"); - return new AuthenticationTicket(null, properties); - } + if (string.IsNullOrWhiteSpace(accessToken) == true) + { + this._logger.WriteWarning("Access token was not found"); + return new AuthenticationTicket(null, properties); + } - var graphResponse = await this._httpClient.GetAsync(GraphApiEndpoint + "?oauth_token=" + Uri.EscapeDataString(accessToken) + "&m=foursquare&v=" + VersionDate.ToString("yyyyyMMdd"), this.Request.CallCancelled); - graphResponse.EnsureSuccessStatusCode(); + var graphResponse = await this._httpClient.GetAsync(GraphApiEndpoint + "?oauth_token=" + Uri.EscapeDataString(accessToken) + "&m=foursquare&v=" + VersionDate.ToString("yyyyyMMdd"), this.Request.CallCancelled); + graphResponse.EnsureSuccessStatusCode(); - var accountstring = await graphResponse.Content.ReadAsStringAsync(); - var accountInformation = JObject.Parse(accountstring); - var user = (JObject)accountInformation["response"]["user"]; + var accountstring = await graphResponse.Content.ReadAsStringAsync(); + var accountInformation = JObject.Parse(accountstring); + var user = (JObject)accountInformation["response"]["user"]; - var context = new FoursquareAuthenticatedContext(this.Context, user, accessToken); + var context = new FoursquareAuthenticatedContext(this.Context, user, accessToken); - context.Identity = new ClaimsIdentity( - new[] + context.Identity = new ClaimsIdentity( + new[] { new Claim(ClaimTypes.NameIdentifier, context.Id, XmlSchemaString, this.Options.AuthenticationType), new Claim(ClaimTypes.Name, context.Name, XmlSchemaString, this.Options.AuthenticationType), new Claim("urn:foursquare:id", context.Id, XmlSchemaString, this.Options.AuthenticationType), new Claim("urn:foursquare:name", context.Name, XmlSchemaString, this.Options.AuthenticationType), }, - this.Options.AuthenticationType, - ClaimsIdentity.DefaultNameClaimType, - ClaimsIdentity.DefaultRoleClaimType); + this.Options.AuthenticationType, + ClaimsIdentity.DefaultNameClaimType, + ClaimsIdentity.DefaultRoleClaimType); - if (string.IsNullOrWhiteSpace(context.Email) == false) - { - context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, XmlSchemaString, this.Options.AuthenticationType)); - } + if (string.IsNullOrWhiteSpace(context.Email) == false) + { + context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, XmlSchemaString, this.Options.AuthenticationType)); + } - if (string.IsNullOrWhiteSpace(context.Twitter) == false) - { - context.Identity.AddClaim(new Claim("urn:foursquare:twitter", context.Twitter, XmlSchemaString, this.Options.AuthenticationType)); - } + if (string.IsNullOrWhiteSpace(context.Twitter) == false) + { + context.Identity.AddClaim(new Claim("urn:foursquare:twitter", context.Twitter, XmlSchemaString, this.Options.AuthenticationType)); + } - await this.Options.Provider.Authenticated(context); + await this.Options.Provider.Authenticated(context); - context.Properties = properties; + context.Properties = properties; - return new AuthenticationTicket(context.Identity, context.Properties); - } - catch (Exception ex) - { - this._logger.WriteWarning("Authentication failed", ex); - return new AuthenticationTicket(null, properties); - } - } + return new AuthenticationTicket(context.Identity, context.Properties); + } + catch (Exception ex) + { + this._logger.WriteWarning("Authentication failed", ex); + return new AuthenticationTicket(null, properties); + } + } - protected override Task ApplyResponseChallengeAsync() - { - this._logger.WriteVerbose("ApplyResponseChallenge"); + protected override Task ApplyResponseChallengeAsync() + { + this._logger.WriteVerbose("ApplyResponseChallenge"); - if (this.Response.StatusCode != (int)HttpStatusCode.Unauthorized) - { - return Task.FromResult(null); - } + if (this.Response.StatusCode != (int)HttpStatusCode.Unauthorized) + { + return Task.FromResult(null); + } - var challenge = Helper.LookupChallenge(this.Options.AuthenticationType, this.Options.AuthenticationMode); + var challenge = Helper.LookupChallenge(this.Options.AuthenticationType, this.Options.AuthenticationMode); - if (challenge != null) - { - var baseUri = this.Request.Scheme + Uri.SchemeDelimiter + this.Request.Host + this.Request.PathBase; - var currentUri = baseUri + this.Request.Path + this.Request.QueryString; - var redirectUri = baseUri + this.Options.CallbackPath; + if (challenge != null) + { + var baseUri = this.Request.Scheme + Uri.SchemeDelimiter + this.Request.Host + this.Request.PathBase; + var currentUri = baseUri + this.Request.Path + this.Request.QueryString; + var redirectUri = baseUri + this.Options.CallbackPath; - var extra = challenge.Properties; + var extra = challenge.Properties; - if (string.IsNullOrEmpty(extra.RedirectUri) == true) - { - extra.RedirectUri = currentUri; - } + if (string.IsNullOrEmpty(extra.RedirectUri) == true) + { + extra.RedirectUri = currentUri; + } - // OAuth2 10.12 CSRF - this.GenerateCorrelationId(extra); + // OAuth2 10.12 CSRF + this.GenerateCorrelationId(extra); - var state = this.Options.StateDataFormat.Protect(extra); + var state = this.Options.StateDataFormat.Protect(extra); - var authorizationEndpoint = AuthorizationEndpoint + - "?client_id=" + Uri.EscapeDataString(this.Options.ClientId) + - "&response_type=code" + - "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + - "&state=" + Uri.EscapeDataString(state); + var authorizationEndpoint = AuthorizationEndpoint + + "?client_id=" + Uri.EscapeDataString(this.Options.ClientId) + + "&response_type=code" + + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + + "&state=" + Uri.EscapeDataString(state); - this.Response.Redirect(authorizationEndpoint); - } + this.Response.Redirect(authorizationEndpoint); + } - return Task.FromResult(null); - } + return Task.FromResult(null); + } - public async Task InvokeReturnPathAsync() - { - this._logger.WriteVerbose("InvokeReturnPath"); + public async Task InvokeReturnPathAsync() + { + this._logger.WriteVerbose("InvokeReturnPath"); - var model = await this.AuthenticateAsync(); + var model = await this.AuthenticateAsync(); - var context = new FoursquareReturnEndpointContext(Context, model); - context.SignInAsAuthenticationType = this.Options.SignInAsAuthenticationType; - context.RedirectUri = model.Properties.RedirectUri; + var context = new FoursquareReturnEndpointContext(Context, model); + context.SignInAsAuthenticationType = this.Options.SignInAsAuthenticationType; + context.RedirectUri = model.Properties.RedirectUri; - model.Properties.RedirectUri = null; + model.Properties.RedirectUri = null; - await this.Options.Provider.ReturnEndpoint(context); + await this.Options.Provider.ReturnEndpoint(context); - if ((context.SignInAsAuthenticationType != null) && (context.Identity != null)) - { - var signInIdentity = context.Identity; + if ((context.SignInAsAuthenticationType != null) && (context.Identity != null)) + { + var signInIdentity = context.Identity; - if (string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal) == false) - { - signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); - } + if (string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal) == false) + { + signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); + } - this.Context.Authentication.SignIn(context.Properties, signInIdentity); - } + this.Context.Authentication.SignIn(context.Properties, signInIdentity); + } - if ((context.IsRequestCompleted == false) && (context.RedirectUri != null)) - { - if (context.Identity == null) - { - context.RedirectUri = WebUtilities.AddQueryString(context.RedirectUri, "error", "access_denied"); - } + if ((context.IsRequestCompleted == false) && (context.RedirectUri != null)) + { + if (context.Identity == null) + { + context.RedirectUri = WebUtilities.AddQueryString(context.RedirectUri, "error", "access_denied"); + } - this.Response.Redirect(context.RedirectUri); + this.Response.Redirect(context.RedirectUri); - context.RequestCompleted(); - } + context.RequestCompleted(); + } - return context.IsRequestCompleted; - } + return context.IsRequestCompleted; + } - private string GenerateRedirectUri() - { - var requestPrefix = this.Request.Scheme + "://" + this.Request.Host; - var redirectUri = requestPrefix + this.RequestPathBase + this.Options.CallbackPath; - return redirectUri; - } - } + private string GenerateRedirectUri() + { + var requestPrefix = this.Request.Scheme + "://" + this.Request.Host; + var redirectUri = requestPrefix + this.RequestPathBase + this.Options.CallbackPath; + return redirectUri; + } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs index f12f0d5..300e5f2 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationMiddleware.cs @@ -10,80 +10,80 @@ using Owin.Security.Providers.Foursquare.Provider; namespace Owin.Security.Providers.Foursquare { - public class FoursquareAuthenticationMiddleware : AuthenticationMiddleware - { - private readonly ILogger _logger; - private readonly HttpClient _httpClient; + public class FoursquareAuthenticationMiddleware : AuthenticationMiddleware + { + private readonly ILogger _logger; + private readonly HttpClient _httpClient; - public FoursquareAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, FoursquareAuthenticationOptions options) - : base(next, options) - { - if (string.IsNullOrWhiteSpace(this.Options.ClientId) == true) - { - throw new ArgumentException("The 'ClientId' must be provided."); - } + public FoursquareAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, FoursquareAuthenticationOptions options) + : base(next, options) + { + if (string.IsNullOrWhiteSpace(this.Options.ClientId) == true) + { + throw new ArgumentException("The 'ClientId' must be provided."); + } - if (string.IsNullOrWhiteSpace(this.Options.ClientSecret) == true) - { - throw new ArgumentException("The 'ClientSecret' option must be provided."); - } + if (string.IsNullOrWhiteSpace(this.Options.ClientSecret) == true) + { + throw new ArgumentException("The 'ClientSecret' option must be provided."); + } - this._logger = app.CreateLogger(); + this._logger = app.CreateLogger(); - if (this.Options.Provider == null) - { - this.Options.Provider = new FoursquareAuthenticationProvider(); - } + if (this.Options.Provider == null) + { + this.Options.Provider = new FoursquareAuthenticationProvider(); + } - if (this.Options.StateDataFormat == null) - { - var dataProtector = app.CreateDataProtector(typeof(FoursquareAuthenticationMiddleware).FullName, this.Options.AuthenticationType, "v1"); - this.Options.StateDataFormat = new PropertiesDataFormat(dataProtector); - } + if (this.Options.StateDataFormat == null) + { + var dataProtector = app.CreateDataProtector(typeof(FoursquareAuthenticationMiddleware).FullName, this.Options.AuthenticationType, "v1"); + this.Options.StateDataFormat = new PropertiesDataFormat(dataProtector); + } - if (string.IsNullOrEmpty(this.Options.SignInAsAuthenticationType) == true) - { - this.Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(); - } + if (string.IsNullOrEmpty(this.Options.SignInAsAuthenticationType) == true) + { + this.Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(); + } - this._httpClient = new HttpClient(ResolveHttpMessageHandler(this.Options)); - this._httpClient.Timeout = this.Options.BackchannelTimeout; - this._httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB - } + this._httpClient = new HttpClient(ResolveHttpMessageHandler(this.Options)); + this._httpClient.Timeout = this.Options.BackchannelTimeout; + this._httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB + } - /// - /// Provides the object for processing - /// authentication-related requests. - /// - /// - /// An configured with the - /// supplied to the constructor. - /// - protected override AuthenticationHandler CreateHandler() - { - return new FoursquareAuthenticationHandler(this._httpClient, this._logger); - } + /// + /// Provides the object for processing + /// authentication-related requests. + /// + /// + /// An configured with the + /// supplied to the constructor. + /// + protected override AuthenticationHandler CreateHandler() + { + return new FoursquareAuthenticationHandler(this._httpClient, this._logger); + } - private static HttpMessageHandler ResolveHttpMessageHandler(FoursquareAuthenticationOptions options) - { - var handler = options.BackchannelHttpHandler ?? new WebRequestHandler(); + private static HttpMessageHandler ResolveHttpMessageHandler(FoursquareAuthenticationOptions options) + { + var handler = options.BackchannelHttpHandler ?? new WebRequestHandler(); - // If they provided a validator, apply it or fail. - if (options.BackchannelCertificateValidator != null) - { - // Set the cert validate callback - var webRequestHandler = handler as WebRequestHandler; + // If they provided a validator, apply it or fail. + if (options.BackchannelCertificateValidator != null) + { + // Set the cert validate callback + var webRequestHandler = handler as WebRequestHandler; - if (webRequestHandler == null) - { - throw new InvalidOperationException("Validator Handler Mismatch"); - } + if (webRequestHandler == null) + { + throw new InvalidOperationException("Validator Handler Mismatch"); + } - webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate; - } + webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate; + } - return handler; - } + return handler; + } - } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs index e1356d2..41d8ab9 100644 --- a/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs +++ b/Owin.Security.Providers/Foursquare/FoursquareAuthenticationOptions.cs @@ -6,88 +6,88 @@ using Owin.Security.Providers.Foursquare.Provider; namespace Owin.Security.Providers.Foursquare { - public class FoursquareAuthenticationOptions : AuthenticationOptions - { - /// - /// Initializes a new - /// - public FoursquareAuthenticationOptions() - : base(Constants.DefaultAuthenticationType) - { - this.Caption = Constants.DefaultAuthenticationType; - this.CallbackPath = "/signin-foursquare"; - this.AuthenticationMode = AuthenticationMode.Passive; - this.BackchannelTimeout = TimeSpan.FromSeconds(60); - } + public class FoursquareAuthenticationOptions : AuthenticationOptions + { + /// + /// Initializes a new + /// + public FoursquareAuthenticationOptions() + : base(Constants.DefaultAuthenticationType) + { + this.Caption = Constants.DefaultAuthenticationType; + this.CallbackPath = "/signin-foursquare"; + this.AuthenticationMode = AuthenticationMode.Passive; + this.BackchannelTimeout = TimeSpan.FromSeconds(60); + } - /// - /// Gets or sets the Foursquare supplied Client ID - /// - public string ClientId { get; set; } + /// + /// Gets or sets the Foursquare supplied Client ID + /// + public string ClientId { get; set; } - /// - /// Gets or sets the Foursquare supplied Client Secret - /// - public string ClientSecret { get; set; } + /// + /// Gets or sets the Foursquare supplied Client Secret + /// + public string ClientSecret { get; set; } - /// - /// Gets or sets the a pinned certificate validator to use to validate the endpoints used - /// in back channel communications belong to Foursquare. - /// - /// - /// The pinned certificate validator. - /// - /// - /// 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. - /// - public ICertificateValidator BackchannelCertificateValidator { get; set; } + /// + /// Gets or sets the a pinned certificate validator to use to validate the endpoints used + /// in back channel communications belong to Foursquare. + /// + /// + /// The pinned certificate validator. + /// + /// + /// 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. + /// + public ICertificateValidator BackchannelCertificateValidator { get; set; } - /// - /// Gets or sets timeout value in milliseconds for back channel communications with Foursquare. - /// - /// - /// The back channel timeout in milliseconds. - /// - public TimeSpan BackchannelTimeout { get; set; } + /// + /// Gets or sets timeout value in milliseconds for back channel communications with Foursquare. + /// + /// + /// The back channel timeout in milliseconds. + /// + public TimeSpan BackchannelTimeout { get; set; } - /// - /// The HttpMessageHandler used to communicate with Foursquare. - /// This cannot be set at the same time as BackchannelCertificateValidator unless the value - /// can be downcast to a WebRequestHandler. - /// - public HttpMessageHandler BackchannelHttpHandler { get; set; } + /// + /// The HttpMessageHandler used to communicate with Foursquare. + /// This cannot be set at the same time as BackchannelCertificateValidator unless the value + /// can be downcast to a WebRequestHandler. + /// + public HttpMessageHandler BackchannelHttpHandler { get; set; } - /// - /// 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-foursquare". - /// - public string CallbackPath { get; set; } + /// + /// 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-foursquare". + /// + public string CallbackPath { get; set; } - /// - /// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user - /// . - /// - public string SignInAsAuthenticationType { get; set; } + /// + /// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user + /// . + /// + public string SignInAsAuthenticationType { get; set; } - /// - /// Gets or sets the used in the authentication events - /// - public IFoursquareAuthenticationProvider Provider { get; set; } + /// + /// Gets or sets the used in the authentication events + /// + public IFoursquareAuthenticationProvider Provider { get; set; } - /// - /// Gets or sets the type used to secure data handled by the middleware. - /// - public ISecureDataFormat StateDataFormat { get; set; } + /// + /// Gets or sets the type used to secure data handled by the middleware. + /// + public ISecureDataFormat StateDataFormat { get; set; } - /// - /// Get or sets the text that the user can display on a sign in user interface. - /// - public string Caption - { - get { return this.Description.Caption; } - set { this.Description.Caption = value; } - } - } + /// + /// Get or sets the text that the user can display on a sign in user interface. + /// + public string Caption + { + get { return this.Description.Caption; } + set { this.Description.Caption = value; } + } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs index be337f1..7454588 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs @@ -7,162 +7,162 @@ using Newtonsoft.Json.Linq; namespace Owin.Security.Providers.Foursquare.Provider { - /// - /// Contains information about the login session as well as the user . - /// - public class FoursquareAuthenticatedContext : BaseContext - { - /// - /// Initializes a - /// - /// The OWIN environment - /// The JSON-serialized user + /// + /// Contains information about the login session as well as the user . + /// + public class FoursquareAuthenticatedContext : BaseContext + { + /// + /// Initializes a + /// + /// The OWIN environment + /// The JSON-serialized user /// Foursquare Access token - public FoursquareAuthenticatedContext(IOwinContext context, JObject user, string accessToken) - : base(context) - { - if (user == null) - { - throw new ArgumentNullException("user"); - } + public FoursquareAuthenticatedContext(IOwinContext context, JObject user, string accessToken) + : base(context) + { + if (user == null) + { + throw new ArgumentNullException("user"); + } - this.User = user; - this.AccessToken = accessToken; + this.User = user; + this.AccessToken = accessToken; - var userId = this.User["id"]; + var userId = this.User["id"]; - if (userId == null) - { - throw new ArgumentException("The user does not have an id.", "user"); - } + if (userId == null) + { + throw new ArgumentException("The user does not have an id.", "user"); + } - this.Id = TryGetValue(user, "id"); - this.FirstName = TryGetValue(user, "firstName"); - this.LastName = TryGetValue(user, "lastName"); - this.Name = this.FirstName + " " + this.LastName; - this.Gender = TryGetValue(user, "gender"); - this.Photo = TryGetValue(user, "photo"); - this.Friends = TryGetValue(user, "friends"); - this.HomeCity = TryGetValue(user, "homeCity"); - this.Bio = TryGetValue(user, "bio"); - this.Contact = TryGetValue(user, "contact"); - this.Phone = TryGetValue(JObject.Parse(this.Contact), "phone"); - this.Email = TryGetValue(JObject.Parse(this.Contact), "email"); - this.Twitter = TryGetValue(JObject.Parse(this.Contact), "twitter"); - this.Facebook = TryGetValue(JObject.Parse(this.Contact), "facebook"); - this.Badges = TryGetValue(user, "badges"); - this.Mayorships = TryGetValue(user, "mayorships"); - this.Checkins = TryGetValue(user, "checkins"); - this.Photos = TryGetValue(user, "photos"); - this.Scores = TryGetValue(user, "scores"); - this.Link = "https://foursquare.com/user/" + this.Id; - } + this.Id = TryGetValue(user, "id"); + this.FirstName = TryGetValue(user, "firstName"); + this.LastName = TryGetValue(user, "lastName"); + this.Name = this.FirstName + " " + this.LastName; + this.Gender = TryGetValue(user, "gender"); + this.Photo = TryGetValue(user, "photo"); + this.Friends = TryGetValue(user, "friends"); + this.HomeCity = TryGetValue(user, "homeCity"); + this.Bio = TryGetValue(user, "bio"); + this.Contact = TryGetValue(user, "contact"); + this.Phone = TryGetValue(JObject.Parse(this.Contact), "phone"); + this.Email = TryGetValue(JObject.Parse(this.Contact), "email"); + this.Twitter = TryGetValue(JObject.Parse(this.Contact), "twitter"); + this.Facebook = TryGetValue(JObject.Parse(this.Contact), "facebook"); + this.Badges = TryGetValue(user, "badges"); + this.Mayorships = TryGetValue(user, "mayorships"); + this.Checkins = TryGetValue(user, "checkins"); + this.Photos = TryGetValue(user, "photos"); + this.Scores = TryGetValue(user, "scores"); + this.Link = "https://foursquare.com/user/" + this.Id; + } - /// - /// Gets the JSON-serialized user - /// - /// - /// Contains the Foursquare user obtained from the User Info endpoint. By default this is https://api.foursquare.com/v2/users/self but it can be - /// overridden in the options - /// - public JObject User { get; private set; } - /// - /// Gets the Foursquare access token - /// - public string AccessToken { get; private set; } - /// - /// Gets the Foursquare user ID - /// - public string Id { get; private set; } - /// - /// Gets the user's first name - /// - public string FirstName { get; private set; } - /// - /// Gets the user's last name - /// - public string LastName { get; private set; } - /// - /// Gets the user's full name - /// - public string Name { get; private set; } - /// - /// Gets the user's gender - /// - public string Gender { get; private set; } - /// - /// Gets the user's photo - /// - public string Photo { get; private set; } - /// - /// Gets the user's friends - /// - public string Friends { get; private set; } - /// - /// Gets the user's home city - /// - public string HomeCity { get; private set; } - /// - /// Gets the user's biography - /// - public string Bio { get; private set; } - /// - /// Gets the user's contact - /// - public string Contact { get; private set; } - /// - /// Gets the user's phone - /// - public string Phone { get; private set; } - /// - /// Gets the user's email - /// - public string Email { get; private set; } - /// - /// Gets the user's Twitter handle - /// - public string Twitter { get; private set; } - /// - /// Gets the user's Facebook id - /// - public string Facebook { get; private set; } - /// - /// Gets the user's badges - /// - public string Badges { get; private set; } - /// - /// Gets the user's mayorships - /// - public string Mayorships { get; private set; } - /// - /// Gets the user's checkins - /// - public string Checkins { get; private set; } - /// - /// Gets the user's photos - /// - public string Photos { get; private set; } - /// - /// Gets the user's scores - /// - public string Scores { get; private set; } - /// - /// Gets the user's link - /// - public string Link { get; private set; } - /// - /// Gets the representing the user - /// - public ClaimsIdentity Identity { get; set; } - /// - /// Gets or sets a property bag for common authentication properties - /// - public AuthenticationProperties Properties { get; set; } + /// + /// Gets the JSON-serialized user + /// + /// + /// Contains the Foursquare user obtained from the User Info endpoint. By default this is https://api.foursquare.com/v2/users/self but it can be + /// overridden in the options + /// + public JObject User { get; private set; } + /// + /// Gets the Foursquare access token + /// + public string AccessToken { get; private set; } + /// + /// Gets the Foursquare user ID + /// + public string Id { get; private set; } + /// + /// Gets the user's first name + /// + public string FirstName { get; private set; } + /// + /// Gets the user's last name + /// + public string LastName { get; private set; } + /// + /// Gets the user's full name + /// + public string Name { get; private set; } + /// + /// Gets the user's gender + /// + public string Gender { get; private set; } + /// + /// Gets the user's photo + /// + public string Photo { get; private set; } + /// + /// Gets the user's friends + /// + public string Friends { get; private set; } + /// + /// Gets the user's home city + /// + public string HomeCity { get; private set; } + /// + /// Gets the user's biography + /// + public string Bio { get; private set; } + /// + /// Gets the user's contact + /// + public string Contact { get; private set; } + /// + /// Gets the user's phone + /// + public string Phone { get; private set; } + /// + /// Gets the user's email + /// + public string Email { get; private set; } + /// + /// Gets the user's Twitter handle + /// + public string Twitter { get; private set; } + /// + /// Gets the user's Facebook id + /// + public string Facebook { get; private set; } + /// + /// Gets the user's badges + /// + public string Badges { get; private set; } + /// + /// Gets the user's mayorships + /// + public string Mayorships { get; private set; } + /// + /// Gets the user's checkins + /// + public string Checkins { get; private set; } + /// + /// Gets the user's photos + /// + public string Photos { get; private set; } + /// + /// Gets the user's scores + /// + public string Scores { get; private set; } + /// + /// Gets the user's link + /// + public string Link { get; private set; } + /// + /// Gets the representing the user + /// + public ClaimsIdentity Identity { get; set; } + /// + /// Gets or sets a property bag for common authentication properties + /// + public AuthenticationProperties Properties { get; set; } - private static string TryGetValue(JObject user, string propertyName) - { - JToken value; - return user.TryGetValue(propertyName, out value) ? value.ToString() : null; - } - } + private static string TryGetValue(JObject user, string propertyName) + { + JToken value; + return user.TryGetValue(propertyName, out value) ? value.ToString() : null; + } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs index 8890a96..841cf2e 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticationProvider.cs @@ -3,48 +3,48 @@ using System.Threading.Tasks; namespace Owin.Security.Providers.Foursquare.Provider { - /// - /// Default implementation. - /// - public class FoursquareAuthenticationProvider : IFoursquareAuthenticationProvider - { - /// - /// Initializes a - /// - public FoursquareAuthenticationProvider() - { - this.OnAuthenticated = context => Task.FromResult(null); - this.OnReturnEndpoint = context => Task.FromResult(null); - } + /// + /// Default implementation. + /// + public class FoursquareAuthenticationProvider : IFoursquareAuthenticationProvider + { + /// + /// Initializes a + /// + public FoursquareAuthenticationProvider() + { + this.OnAuthenticated = context => Task.FromResult(null); + this.OnReturnEndpoint = context => Task.FromResult(null); + } - /// - /// Gets or sets the function that is invoked when the Authenticated method is invoked. - /// - public Func OnAuthenticated { get; set; } + /// + /// Gets or sets the function that is invoked when the Authenticated method is invoked. + /// + public Func OnAuthenticated { get; set; } - /// - /// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked. - /// - public Func OnReturnEndpoint { get; set; } + /// + /// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked. + /// + public Func OnReturnEndpoint { get; set; } - /// + /// /// Invoked whenever Foursquare succesfully authenticates a user - /// - /// Contains information about the login session as well as the user . - /// A representing the completed operation. - public virtual Task Authenticated(FoursquareAuthenticatedContext context) - { - return this.OnAuthenticated(context); - } + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + public virtual Task Authenticated(FoursquareAuthenticatedContext context) + { + return this.OnAuthenticated(context); + } - /// - /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. - /// - /// - /// A representing the completed operation. - public virtual Task ReturnEndpoint(FoursquareReturnEndpointContext context) - { - return this.OnReturnEndpoint(context); - } - } + /// + /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. + /// + /// + /// A representing the completed operation. + public virtual Task ReturnEndpoint(FoursquareReturnEndpointContext context) + { + return this.OnReturnEndpoint(context); + } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs index 27fd33f..6ec9a33 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareReturnEndpointContext.cs @@ -4,19 +4,19 @@ using Microsoft.Owin.Security.Provider; namespace Owin.Security.Providers.Foursquare.Provider { - /// - /// Provides context information to middleware providers. - /// - public class FoursquareReturnEndpointContext : ReturnEndpointContext - { - /// - /// - /// - /// OWIN environment - /// The authentication ticket - public FoursquareReturnEndpointContext(IOwinContext context, AuthenticationTicket ticket) - : base(context, ticket) - { - } - } + /// + /// Provides context information to middleware providers. + /// + public class FoursquareReturnEndpointContext : ReturnEndpointContext + { + /// + /// + /// + /// OWIN environment + /// The authentication ticket + public FoursquareReturnEndpointContext(IOwinContext context, AuthenticationTicket ticket) + : base(context, ticket) + { + } + } } \ No newline at end of file diff --git a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs index c6f79f3..c46a554 100644 --- a/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs +++ b/Owin.Security.Providers/Foursquare/Provider/IFoursquareAuthenticationProvider.cs @@ -2,23 +2,23 @@ namespace Owin.Security.Providers.Foursquare.Provider { - /// - /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> - /// - public interface IFoursquareAuthenticationProvider - { - /// + /// + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// + public interface IFoursquareAuthenticationProvider + { + /// /// Invoked whenever Foursquare succesfully authenticates a user - /// - /// Contains information about the login session as well as the user . - /// A representing the completed operation. - Task Authenticated(FoursquareAuthenticatedContext context); + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + Task Authenticated(FoursquareAuthenticatedContext context); - /// - /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. - /// - /// - /// A representing the completed operation. - Task ReturnEndpoint(FoursquareReturnEndpointContext context); - } + /// + /// Invoked prior to the being saved in a local cookie and the browser being redirected to the originally requested URL. + /// + /// + /// A representing the completed operation. + Task ReturnEndpoint(FoursquareReturnEndpointContext context); + } } \ No newline at end of file From f6177258991eaf807e8cd6eb196537e135ed3ff0 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Wed, 25 Mar 2015 13:58:09 +0000 Subject: [PATCH 5/6] Tweaked context data types. Instead of storing Json as a string, use a JObject. This will make it easier to attain data for the user. --- .../FoursquareAuthenticatedContext.cs | 16 ++++++++-------- ...-OwinOAuthProvidersDemo-20131113093838.mdf | Bin 3211264 -> 3211264 bytes ...nOAuthProvidersDemo-20131113093838_log.ldf | Bin 1048576 -> 1048576 bytes 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs index 7454588..6596fba 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs @@ -41,15 +41,15 @@ namespace Owin.Security.Providers.Foursquare.Provider this.LastName = TryGetValue(user, "lastName"); this.Name = this.FirstName + " " + this.LastName; this.Gender = TryGetValue(user, "gender"); - this.Photo = TryGetValue(user, "photo"); + this.Photo = (JObject)user["photo"]; this.Friends = TryGetValue(user, "friends"); this.HomeCity = TryGetValue(user, "homeCity"); this.Bio = TryGetValue(user, "bio"); - this.Contact = TryGetValue(user, "contact"); - this.Phone = TryGetValue(JObject.Parse(this.Contact), "phone"); - this.Email = TryGetValue(JObject.Parse(this.Contact), "email"); - this.Twitter = TryGetValue(JObject.Parse(this.Contact), "twitter"); - this.Facebook = TryGetValue(JObject.Parse(this.Contact), "facebook"); + this.Contact = (JObject)user["contact"]; + this.Phone = TryGetValue(Contact, "phone"); + this.Email = TryGetValue(Contact, "email"); + this.Twitter = TryGetValue(Contact, "twitter"); + this.Facebook = TryGetValue(Contact, "facebook"); this.Badges = TryGetValue(user, "badges"); this.Mayorships = TryGetValue(user, "mayorships"); this.Checkins = TryGetValue(user, "checkins"); @@ -93,7 +93,7 @@ namespace Owin.Security.Providers.Foursquare.Provider /// /// Gets the user's photo /// - public string Photo { get; private set; } + public JObject Photo { get; private set; } /// /// Gets the user's friends /// @@ -109,7 +109,7 @@ namespace Owin.Security.Providers.Foursquare.Provider /// /// Gets the user's contact /// - public string Contact { get; private set; } + public JObject Contact { get; private set; } /// /// Gets the user's phone /// diff --git a/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838.mdf b/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838.mdf index 9c13e273623639ea9bcecfb4355cbdbc13599d5b..93d2e48cc2b4de74808e50270618c9e798058c12 100644 GIT binary patch delta 327 zcmZ9_zfQtX6vy#Cl0fFmYgYkfqPy z!gFYX-^PRx&pDsroZoPQ;8O;8Q##U#5t-UF=28e|U*+e*G|gv z>3X8&SXybU=)>x={N07v#9K?c>Lnlgo!GVIPw2O2o+F`CN zR8d16XE4x!iE}h@flIWI{_EfhU1(Ua;h={;2DpZc8{Fa!_ZVV?hqdQCeti7`%3@8= delta 329 zcmYMtJx&5q6o%n@t_moM;NXBFa%To~5Pz_shgH~Fum}3FvL?4+0d9b3K}!PFG&FWl z$Oc@2iM|sP_;Q})ik6x5H*f1z0zmO}A5naf^8iJ5O6{a)e5SsE<JBR&?`U_RxS8F=i{M1<-j z_ch;6v{5_njGEwi6G`CS@>uS9LD)VF*&d#ezy};3<6Vij6UVC(%Ix&q;W8?7s4`}& zybJlbN_@bz+EE#jS+IVY`NpvrX{5n6c6Q-lnY8(O(x|{L0#w0T`4a9uFQy@wsznj@ z=}4QO&u_y?l?9GQ2w@wot#pL2Lsnzoa~mnyBgTPeJwRHh>$v0=pAv@!=_%=~GXtj=lIINKSOD zIL@Dnf@GP2;v16e<(<*ok9>>-F59UyPkJqC>a{k_Jf72Bv}wNUqWKwSMSz4yPGv$} z&|Fq&E=IH~w$j@vzYFM6xDXnGxZMUfd7Ma~6CDERQs}B4YLR&Oj@3F$^Gyyfc$J#& z=S+87?Q~r7>u@W(0@w|G7%2H&{kJXrx6)4xu#W{=6#RO}pi9^nAr1Ro!V|Xerc~Vk zx6%RmpQ+d5zEW!2wAJSiY}vEIu(RXK7A8wwaeL)Ahhg?`wuf*iYRH|<%B|d0EjCd>hS@zJZt_7k#f=HCSrvU47#Ns<5E;k=IS_FMh82@@*ff~F zu}*Z9oxGXt&-6rPMj6JC>9NX;29pgOFTk+^yY^&(GM3HJViOn@9T^!I7Gp6KBF?~Y z7;GpL2eP4?PqQbmP@t3A9 Date: Thu, 26 Mar 2015 10:26:15 +0000 Subject: [PATCH 6/6] Removed inaccurate comment --- .../Foursquare/Provider/FoursquareAuthenticatedContext.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs index 6596fba..04b9a28 100644 --- a/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs +++ b/Owin.Security.Providers/Foursquare/Provider/FoursquareAuthenticatedContext.cs @@ -62,8 +62,7 @@ namespace Owin.Security.Providers.Foursquare.Provider /// Gets the JSON-serialized user /// /// - /// Contains the Foursquare user obtained from the User Info endpoint. By default this is https://api.foursquare.com/v2/users/self but it can be - /// overridden in the options + /// Contains the Foursquare user obtained from the User Info endpoint https://api.foursquare.com/v2/users/self /// public JObject User { get; private set; } ///