From 85dea7de89872586cdcb6095c589692ed23413ad Mon Sep 17 00:00:00 2001 From: Dave Timmins Date: Thu, 18 Sep 2014 12:02:41 +1200 Subject: [PATCH] added ArcGIS Online provider --- .../ArcGISOnlineAuthenticationExtensions.cs | 29 +++ .../ArcGISOnlineAuthenticationHandler.cs | 218 ++++++++++++++++++ .../ArcGISOnlineAuthenticationMiddleware.cs | 87 +++++++ .../ArcGISOnlineAuthenticationOptions.cs | 145 ++++++++++++ .../ArcGISOnline/Constants.cs | 7 + .../ArcGISOnlineAuthenticatedContext.cs | 75 ++++++ .../ArcGISOnlineAuthenticationProvider.cs | 50 ++++ .../ArcGISOnlineReturnEndpointContext.cs | 26 +++ .../ArcGISOnline/Provider/ArcGISOnlineUser.cs | 16 ++ .../IArcGISOnlineAuthenticationProvider.cs | 24 ++ .../Owin.Security.Providers.csproj | 10 + .../App_Start/Startup.Auth.cs | 5 + 12 files changed, 692 insertions(+) create mode 100644 Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationExtensions.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationHandler.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationMiddleware.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationOptions.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Constants.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticatedContext.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticationProvider.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineReturnEndpointContext.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineUser.cs create mode 100644 Owin.Security.Providers/ArcGISOnline/Provider/IArcGISOnlineAuthenticationProvider.cs diff --git a/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationExtensions.cs b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationExtensions.cs new file mode 100644 index 0000000..d5d6367 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationExtensions.cs @@ -0,0 +1,29 @@ +using System; + +namespace Owin.Security.Providers.ArcGISOnline +{ + public static class ArcGISOnlineAuthenticationExtensions + { + public static IAppBuilder UseArcGISOnlineAuthentication(this IAppBuilder app, + ArcGISOnlineAuthenticationOptions options) + { + if (app == null) + throw new ArgumentNullException("app"); + if (options == null) + throw new ArgumentNullException("options"); + + app.Use(typeof(ArcGISOnlineAuthenticationMiddleware), app, options); + + return app; + } + + public static IAppBuilder UseArcGISOnlineAuthentication(this IAppBuilder app, string clientId, string clientSecret) + { + return app.UseArcGISOnlineAuthentication(new ArcGISOnlineAuthenticationOptions + { + ClientId = clientId, + ClientSecret = clientSecret + }); + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationHandler.cs b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationHandler.cs new file mode 100644 index 0000000..b9f9ee1 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationHandler.cs @@ -0,0 +1,218 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.Owin; +using Microsoft.Owin.Infrastructure; +using Microsoft.Owin.Logging; +using Microsoft.Owin.Security; +using Microsoft.Owin.Security.Infrastructure; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Owin.Security.Providers.ArcGISOnline +{ + public class ArcGISOnlineAuthenticationHandler : AuthenticationHandler + { + private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; + + private readonly ILogger logger; + private readonly HttpClient httpClient; + + public ArcGISOnlineAuthenticationHandler(HttpClient httpClient, ILogger logger) + { + this.httpClient = httpClient; + this.logger = logger; + } + + protected override async Task AuthenticateCoreAsync() + { + AuthenticationProperties properties = null; + + try + { + string code = null; + + IReadableStringCollection query = Request.Query; + IList values = query.GetValues("code"); + if (values != null && values.Count == 1) + { + code = values[0]; + } + + string requestPrefix = Request.Scheme + "://" + Request.Host; + string redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; + + // Build up the body for the token request + var body = new List>(); + body.Add(new KeyValuePair("code", code)); + body.Add(new KeyValuePair("redirect_uri", redirectUri)); + body.Add(new KeyValuePair("client_id", Options.ClientId)); + body.Add(new KeyValuePair("client_secret", Options.ClientSecret)); + body.Add(new KeyValuePair("grant_type", "authorization_code")); + + // Request the token + var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.Endpoints.TokenEndpoint); + requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + requestMessage.Content = new FormUrlEncodedContent(body); + HttpResponseMessage tokenResponse = await httpClient.SendAsync(requestMessage); + tokenResponse.EnsureSuccessStatusCode(); + string text = await tokenResponse.Content.ReadAsStringAsync(); + + // Deserializes the token response + dynamic response = JsonConvert.DeserializeObject(text); + string accessToken = (string)response.access_token; + + // Get the ArcGISOnline user + HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, Options.Endpoints.UserInfoEndpoint + "?f=json&token=" + Uri.EscapeDataString(accessToken)); + userRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + HttpResponseMessage userResponse = await httpClient.SendAsync(userRequest, Request.CallCancelled); + userResponse.EnsureSuccessStatusCode(); + text = await userResponse.Content.ReadAsStringAsync(); + var user = JsonConvert.DeserializeObject(text); + + var context = new ArcGISOnlineAuthenticatedContext(Context, user, accessToken); + context.Identity = new ClaimsIdentity( + Options.AuthenticationType, + ClaimsIdentity.DefaultNameClaimType, + ClaimsIdentity.DefaultRoleClaimType); + if (!string.IsNullOrEmpty(context.Id)) + { + context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, XmlSchemaString, Options.AuthenticationType)); + } + if (!string.IsNullOrEmpty(context.UserName)) + { + context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.UserName, XmlSchemaString, Options.AuthenticationType)); + } + if (!string.IsNullOrEmpty(context.Email)) + { + context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, XmlSchemaString, Options.AuthenticationType)); + } + if (!string.IsNullOrEmpty(context.Name)) + { + context.Identity.AddClaim(new Claim("urn:ArcGISOnline:name", context.Name, XmlSchemaString, Options.AuthenticationType)); + } + if (!string.IsNullOrEmpty(context.Link)) + { + context.Identity.AddClaim(new Claim("urn:ArcGISOnline:url", context.Link, XmlSchemaString, Options.AuthenticationType)); + } + string baseUri = + Request.Scheme + + Uri.SchemeDelimiter + + Request.Host + + Request.PathBase; + + context.Properties = new AuthenticationProperties + { + RedirectUri = baseUri + + "/Account/ExternalLoginCallback" + }; + + await Options.Provider.Authenticated(context); + + return new AuthenticationTicket(context.Identity, context.Properties); + } + catch (Exception ex) + { + logger.WriteError(ex.Message); + } + return new AuthenticationTicket(null, properties); + } + + protected override Task ApplyResponseChallengeAsync() + { + if (Response.StatusCode != 401) + { + return Task.FromResult(null); + } + + AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode); + + if (challenge != null) + { + string baseUri = + Request.Scheme + + Uri.SchemeDelimiter + + Request.Host + + Request.PathBase; + + string currentUri = + baseUri + + Request.Path + + Request.QueryString; + + string redirectUri = + baseUri + + Options.CallbackPath; + + // comma separated + string scope = string.Join(",", Options.Scope); + + string authorizationEndpoint = + Options.Endpoints.AuthorizationEndpoint + + "?client_id=" + Uri.EscapeDataString(Options.ClientId) + + "&response_type=" + Uri.EscapeDataString(scope) + + "&redirect_uri=" + Uri.EscapeDataString(redirectUri); + + Response.Redirect(authorizationEndpoint); + } + + return Task.FromResult(null); + } + + public override async Task InvokeAsync() + { + return await InvokeReplyPathAsync(); + } + + private async Task InvokeReplyPathAsync() + { + if (Options.CallbackPath.HasValue && Options.CallbackPath == Request.Path) + { + // TODO: error responses + + AuthenticationTicket ticket = await AuthenticateAsync(); + if (ticket == null) + { + logger.WriteWarning("Invalid return state, unable to redirect."); + Response.StatusCode = 500; + return true; + } + + var context = new ArcGISOnlineReturnEndpointContext(Context, ticket); + context.SignInAsAuthenticationType = Options.SignInAsAuthenticationType; + context.RedirectUri = ticket.Properties.RedirectUri; + + await Options.Provider.ReturnEndpoint(context); + + if (context.SignInAsAuthenticationType != null && + context.Identity != null) + { + ClaimsIdentity grantIdentity = context.Identity; + if (!string.Equals(grantIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) + { + grantIdentity = new ClaimsIdentity(grantIdentity.Claims, context.SignInAsAuthenticationType, grantIdentity.NameClaimType, grantIdentity.RoleClaimType); + } + Context.Authentication.SignIn(context.Properties, grantIdentity); + } + + if (!context.IsRequestCompleted && context.RedirectUri != null) + { + string redirectUri = context.RedirectUri; + if (context.Identity == null) + { + // add a redirect hint that sign-in failed in some way + redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied"); + } + Response.Redirect(redirectUri); + context.RequestCompleted(); + } + + return context.IsRequestCompleted; + } + return false; + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationMiddleware.cs b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationMiddleware.cs new file mode 100644 index 0000000..0460921 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationMiddleware.cs @@ -0,0 +1,87 @@ +using System; +using System.Globalization; +using System.Net.Http; +using Microsoft.Owin; +using Microsoft.Owin.Logging; +using Microsoft.Owin.Security; +using Microsoft.Owin.Security.DataHandler; +using Microsoft.Owin.Security.DataProtection; +using Microsoft.Owin.Security.Infrastructure; +using Owin.Security.Providers.Properties; + +namespace Owin.Security.Providers.ArcGISOnline +{ + public class ArcGISOnlineAuthenticationMiddleware : AuthenticationMiddleware + { + private readonly HttpClient httpClient; + private readonly ILogger logger; + + public ArcGISOnlineAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, + ArcGISOnlineAuthenticationOptions options) + : base(next, options) + { + if (String.IsNullOrWhiteSpace(Options.ClientId)) + throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, + Resources.Exception_OptionMustBeProvided, "ClientId")); + if (String.IsNullOrWhiteSpace(Options.ClientSecret)) + throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, + Resources.Exception_OptionMustBeProvided, "ClientSecret")); + + logger = app.CreateLogger(); + + if (Options.Provider == null) + Options.Provider = new ArcGISOnlineAuthenticationProvider(); + + if (Options.StateDataFormat == null) + { + IDataProtector dataProtector = app.CreateDataProtector( + typeof (ArcGISOnlineAuthenticationMiddleware).FullName, + Options.AuthenticationType, "v2"); + Options.StateDataFormat = new PropertiesDataFormat(dataProtector); + } + + if (String.IsNullOrEmpty(Options.SignInAsAuthenticationType)) + Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(); + + httpClient = new HttpClient(ResolveHttpMessageHandler(Options)) + { + Timeout = Options.BackchannelTimeout, + MaxResponseContentBufferSize = 1024*1024*10, + }; + httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft Owin ArcGISOnline middleware"); + httpClient.DefaultRequestHeaders.ExpectContinue = false; + } + + /// + /// Provides the object for processing + /// authentication-related requests. + /// + /// + /// An configured with the + /// supplied to the constructor. + /// + protected override AuthenticationHandler CreateHandler() + { + return new ArcGISOnlineAuthenticationHandler(httpClient, logger); + } + + private HttpMessageHandler ResolveHttpMessageHandler(ArcGISOnlineAuthenticationOptions options) + { + HttpMessageHandler 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 (webRequestHandler == null) + { + throw new InvalidOperationException(Resources.Exception_ValidatorHandlerMismatch); + } + webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate; + } + + return handler; + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationOptions.cs b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationOptions.cs new file mode 100644 index 0000000..fc4da33 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/ArcGISOnlineAuthenticationOptions.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using Microsoft.Owin; +using Microsoft.Owin.Security; + +namespace Owin.Security.Providers.ArcGISOnline +{ + public class ArcGISOnlineAuthenticationOptions : AuthenticationOptions + { + public class ArcGISOnlineAuthenticationEndpoints + { + /// + /// Endpoint which is used to redirect users to request ArcGISOnline access + /// + /// + /// Defaults to https://www.arcgis.com/sharing/oauth2/authorize + /// + public string AuthorizationEndpoint { get; set; } + + /// + /// Endpoint which is used to exchange code for access token + /// + /// + /// Defaults to https://www.arcgis.com/sharing/oauth2/token + /// + public string TokenEndpoint { get; set; } + + /// + /// Endpoint which is used to obtain user information after authentication + /// + /// + /// Defaults to https://www.arcgis.com/sharing/rest/accounts/self + /// + public string UserInfoEndpoint { get; set; } + } + + private const string AuthorizationEndPoint = "https://www.arcgis.com/sharing/oauth2/authorize"; + private const string TokenEndpoint = "https://www.arcgis.com/sharing/oauth2/token"; + private const string UserInfoEndpoint = "https://www.arcgis.com/sharing/rest/accounts/self"; + + /// + /// Gets or sets the a pinned certificate validator to use to validate the endpoints used + /// in back channel communications belong to ArcGISOnline. + /// + /// + /// 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; } + + /// + /// The HttpMessageHandler used to communicate with ArcGISOnline. + /// This cannot be set at the same time as BackchannelCertificateValidator unless the value + /// can be downcast to a WebRequestHandler. + /// + public HttpMessageHandler BackchannelHttpHandler { get; set; } + + /// + /// Gets or sets timeout value in milliseconds for back channel communications with ArcGISOnline. + /// + /// + /// The back channel timeout in milliseconds. + /// + public TimeSpan BackchannelTimeout { 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-ArcGISOnline". + /// + public PathString CallbackPath { get; set; } + + /// + /// Get or sets the text that the user can display on a sign in user interface. + /// + public string Caption + { + get { return Description.Caption; } + set { Description.Caption = value; } + } + + /// + /// Gets or sets the ArcGISOnline supplied Client ID + /// + public string ClientId { get; set; } + + /// + /// Gets or sets the ArcGISOnline supplied Client Secret + /// + public string ClientSecret { get; set; } + + /// + /// Gets the sets of OAuth endpoints used to authenticate against ArcGISOnline. Overriding these endpoints allows you to use ArcGISOnline Enterprise for + /// authentication. + /// + public ArcGISOnlineAuthenticationEndpoints Endpoints { get; set; } + + /// + /// Gets or sets the used in the authentication events + /// + public IArcGISOnlineAuthenticationProvider Provider { get; set; } + + /// + /// A list of permissions to request. + /// + public IList Scope { get; private 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 type used to secure data handled by the middleware. + /// + public ISecureDataFormat StateDataFormat { get; set; } + + /// + /// Initializes a new + /// + public ArcGISOnlineAuthenticationOptions() + : base("ArcGIS Online") + { + Caption = Constants.DefaultAuthenticationType; + CallbackPath = new PathString("/signin-arcgis-online"); + AuthenticationMode = AuthenticationMode.Passive; + Scope = new List + { + "code" + }; + BackchannelTimeout = TimeSpan.FromSeconds(60); + Endpoints = new ArcGISOnlineAuthenticationEndpoints + { + AuthorizationEndpoint = AuthorizationEndPoint, + TokenEndpoint = TokenEndpoint, + UserInfoEndpoint = UserInfoEndpoint + }; + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/Constants.cs b/Owin.Security.Providers/ArcGISOnline/Constants.cs new file mode 100644 index 0000000..4134be6 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Constants.cs @@ -0,0 +1,7 @@ +namespace Owin.Security.Providers.ArcGISOnline +{ + internal static class Constants + { + public const string DefaultAuthenticationType = "ArcGIS Online"; + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticatedContext.cs b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticatedContext.cs new file mode 100644 index 0000000..074a970 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticatedContext.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System; +using System.Globalization; +using System.Security.Claims; +using System.Linq; +using Microsoft.Owin; +using Microsoft.Owin.Security; +using Microsoft.Owin.Security.Provider; +using Newtonsoft.Json.Linq; +using Owin.Security.Providers.ArcGISOnline.Provider; + +namespace Owin.Security.Providers.ArcGISOnline +{ + /// + /// Contains information about the login session as well as the user . + /// + public class ArcGISOnlineAuthenticatedContext : BaseContext + { + /// + /// Initializes a + /// + /// The OWIN environment + /// The ArcGIS Online user + /// ArcGISOnline Access token + public ArcGISOnlineAuthenticatedContext(IOwinContext context, ArcGISOnlineUser user, string accessToken) + : base(context) + { + AccessToken = accessToken; + + Id = user.user.username; + Name = user.user.fullName; + Link = "https://www.arcgis.com/sharing/rest/community/users/" + Id; + UserName = Id; + Email = user.user.email; + } + + /// + /// Gets the ArcGISOnline access token + /// + public string AccessToken { get; private set; } + + /// + /// Gets the ArcGISOnline user ID + /// + public string Id { get; private set; } + + /// + /// Gets the user's name + /// + public string Name { get; private set; } + + /// + /// Gets the user's email + /// + public string Email { get; private set; } + + public string Link { get; private set; } + + /// + /// Gets the ArcGISOnline username + /// + public string UserName { 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; } + } +} diff --git a/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticationProvider.cs b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticationProvider.cs new file mode 100644 index 0000000..d122109 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineAuthenticationProvider.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; + +namespace Owin.Security.Providers.ArcGISOnline +{ + /// + /// Default implementation. + /// + public class ArcGISOnlineAuthenticationProvider : IArcGISOnlineAuthenticationProvider + { + /// + /// Initializes a + /// + public ArcGISOnlineAuthenticationProvider() + { + OnAuthenticated = context => Task.FromResult(null); + 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 ArcGISOnline succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + public virtual Task Authenticated(ArcGISOnlineAuthenticatedContext context) + { + return 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(ArcGISOnlineReturnEndpointContext context) + { + return OnReturnEndpoint(context); + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineReturnEndpointContext.cs b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineReturnEndpointContext.cs new file mode 100644 index 0000000..6e5b912 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineReturnEndpointContext.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using Microsoft.Owin; +using Microsoft.Owin.Security; +using Microsoft.Owin.Security.Provider; + +namespace Owin.Security.Providers.ArcGISOnline +{ + /// + /// Provides context information to middleware providers. + /// + public class ArcGISOnlineReturnEndpointContext : ReturnEndpointContext + { + /// + /// + /// + /// OWIN environment + /// The authentication ticket + public ArcGISOnlineReturnEndpointContext( + IOwinContext context, + AuthenticationTicket ticket) + : base(context, ticket) + { + } + } +} diff --git a/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineUser.cs b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineUser.cs new file mode 100644 index 0000000..3dd3a03 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Provider/ArcGISOnlineUser.cs @@ -0,0 +1,16 @@ +using System; + +namespace Owin.Security.Providers.ArcGISOnline.Provider +{ + public class ArcGISOnlineUser + { + public User user { get; set; } + } + + public class User + { + public string username { get; set; } + public string fullName { get; set; } + public string email { get; set; } + } +} diff --git a/Owin.Security.Providers/ArcGISOnline/Provider/IArcGISOnlineAuthenticationProvider.cs b/Owin.Security.Providers/ArcGISOnline/Provider/IArcGISOnlineAuthenticationProvider.cs new file mode 100644 index 0000000..f8b2164 --- /dev/null +++ b/Owin.Security.Providers/ArcGISOnline/Provider/IArcGISOnlineAuthenticationProvider.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; + +namespace Owin.Security.Providers.ArcGISOnline +{ + /// + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// + public interface IArcGISOnlineAuthenticationProvider + { + /// + /// Invoked whenever ArcGISOnline succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + Task Authenticated(ArcGISOnlineAuthenticatedContext 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(ArcGISOnlineReturnEndpointContext context); + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/Owin.Security.Providers.csproj b/Owin.Security.Providers/Owin.Security.Providers.csproj index ef7a3e9..74cfa76 100644 --- a/Owin.Security.Providers/Owin.Security.Providers.csproj +++ b/Owin.Security.Providers/Owin.Security.Providers.csproj @@ -57,6 +57,16 @@ + + + + + + + + + + diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index e8ef803..12125d2 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.Identity; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; +using Owin.Security.Providers.ArcGISOnline; using Owin.Security.Providers.Buffer; using Owin.Security.Providers.GitHub; using Owin.Security.Providers.GooglePlus; @@ -113,6 +114,10 @@ namespace OwinOAuthProvidersDemo // ClientId = "", // ClientSecret = "" //}); + + app.UseArcGISOnlineAuthentication( + clientId: "", + clientSecret: ""); } } } \ No newline at end of file