From 87c208f7844ff68189fe94e8fb48b20e9efabd57 Mon Sep 17 00:00:00 2001 From: takashi uesaka Date: Thu, 23 Jul 2015 19:28:17 +0900 Subject: [PATCH] Add Backlog provider --- .../BacklogAuthenticationExtensions.cs | 29 +++ .../Backlog/BacklogAuthenticationHandler.cs | 234 ++++++++++++++++++ .../BacklogAuthenticationMiddleware.cs | 88 +++++++ .../Backlog/BacklogAuthenticationOptions.cs | 135 ++++++++++ Owin.Security.Providers/Backlog/Constants.cs | 7 + .../Provider/BacklogAuthenticatedContext.cs | 105 ++++++++ .../Provider/BacklogAuthenticationProvider.cs | 50 ++++ .../Provider/BacklogReturnEndpointContext.cs | 26 ++ .../IGBacklogAuthenticationProvider.cs | 24 ++ .../Owin.Security.Providers.csproj | 9 + .../App_Start/Startup.Auth.cs | 22 +- 11 files changed, 726 insertions(+), 3 deletions(-) create mode 100644 Owin.Security.Providers/Backlog/BacklogAuthenticationExtensions.cs create mode 100644 Owin.Security.Providers/Backlog/BacklogAuthenticationHandler.cs create mode 100644 Owin.Security.Providers/Backlog/BacklogAuthenticationMiddleware.cs create mode 100644 Owin.Security.Providers/Backlog/BacklogAuthenticationOptions.cs create mode 100644 Owin.Security.Providers/Backlog/Constants.cs create mode 100644 Owin.Security.Providers/Backlog/Provider/BacklogAuthenticatedContext.cs create mode 100644 Owin.Security.Providers/Backlog/Provider/BacklogAuthenticationProvider.cs create mode 100644 Owin.Security.Providers/Backlog/Provider/BacklogReturnEndpointContext.cs create mode 100644 Owin.Security.Providers/Backlog/Provider/IGBacklogAuthenticationProvider.cs diff --git a/Owin.Security.Providers/Backlog/BacklogAuthenticationExtensions.cs b/Owin.Security.Providers/Backlog/BacklogAuthenticationExtensions.cs new file mode 100644 index 0000000..d26f6e2 --- /dev/null +++ b/Owin.Security.Providers/Backlog/BacklogAuthenticationExtensions.cs @@ -0,0 +1,29 @@ +using System; + +namespace Owin.Security.Providers.Backlog +{ + public static class BacklogAuthenticationExtensions + { + public static IAppBuilder UseBacklogAuthentication(this IAppBuilder app, + BacklogAuthenticationOptions options) + { + if (app == null) + throw new ArgumentNullException("app"); + if (options == null) + throw new ArgumentNullException("options"); + + app.Use(typeof(BacklogAuthenticationMiddleware), app, options); + + return app; + } + + public static IAppBuilder UseBacklogAuthentication(this IAppBuilder app, string clientId, string clientSecret) + { + return app.UseBacklogAuthentication(new BacklogAuthenticationOptions + { + ClientId = clientId, + ClientSecret = clientSecret + }); + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/Backlog/BacklogAuthenticationHandler.cs b/Owin.Security.Providers/Backlog/BacklogAuthenticationHandler.cs new file mode 100644 index 0000000..60c784e --- /dev/null +++ b/Owin.Security.Providers/Backlog/BacklogAuthenticationHandler.cs @@ -0,0 +1,234 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +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; +using Owin.Security.Providers.Backlog; + +namespace Owin.Security.Providers.Backlog +{ + public class BacklogAuthenticationHandler : AuthenticationHandler + { + private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; + + private readonly ILogger logger; + private readonly HttpClient httpClient; + + public BacklogAuthenticationHandler(HttpClient httpClient, ILogger logger) + { + this.httpClient = httpClient; + this.logger = logger; + } + + protected override async Task AuthenticateCoreAsync() + { + AuthenticationProperties properties = null; + + try + { + string code = null; + string state = null; + + IReadableStringCollection query = Request.Query; + IList values = query.GetValues("code"); + if (values != null && values.Count == 1) + { + code = values[0]; + } + values = query.GetValues("state"); + if (values != null && values.Count == 1) + { + state = values[0]; + } + + properties = Options.StateDataFormat.Unprotect(state); + if (properties == null) + { + return null; + } + + // OAuth2 10.12 CSRF + if (!ValidateCorrelationId(properties, logger)) + { + return new AuthenticationTicket(null, properties); + } + + 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("grant_type", "authorization_code")); + 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)); + + // Get token + HttpResponseMessage tokenResponse = + await httpClient.PostAsync(Options.TokenEndpoint, new FormUrlEncodedContent(body)); + tokenResponse.EnsureSuccessStatusCode(); + string text = await tokenResponse.Content.ReadAsStringAsync(); + + // Deserializes the token response + dynamic response = JsonConvert.DeserializeObject(text); + string accessToken = (string)response.access_token; + string expires = (string) response.expires_in; + string refreshToken = null; + if (response.refresh_token != null) + refreshToken = (string) response.refresh_token; + string tokenType = (string)response.token_type; + + // Get the Backlog user + httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(tokenType, Uri.EscapeDataString(accessToken)); + HttpResponseMessage graphResponse = await httpClient.GetAsync( + Options.UserInfoEndpoint, Request.CallCancelled); + + graphResponse.EnsureSuccessStatusCode(); + text = await graphResponse.Content.ReadAsStringAsync(); + JObject user = JObject.Parse(text); + + var context = new BacklogAuthenticatedContext(Context, user, accessToken, expires, refreshToken); + + 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.Name)) + { + context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, context.Name, XmlSchemaString, Options.AuthenticationType)); + } + if (!string.IsNullOrEmpty(context.MailAddress)) + { + context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.MailAddress, XmlSchemaString, Options.AuthenticationType)); + } + + context.Properties = properties; + + 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; + + AuthenticationProperties properties = challenge.Properties; + if (string.IsNullOrEmpty(properties.RedirectUri)) + { + properties.RedirectUri = currentUri; + } + + // OAuth2 10.12 CSRF + GenerateCorrelationId(properties); + + string state = Options.StateDataFormat.Protect(properties); + + string authorizationEndpoint = + Options.AuthorizationEndpoint + + "?response_type=code" + + "&client_id=" + Uri.EscapeDataString(Options.ClientId) + + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + + "&state=" + Uri.EscapeDataString(state); + + 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 BacklogReturnEndpointContext(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/Backlog/BacklogAuthenticationMiddleware.cs b/Owin.Security.Providers/Backlog/BacklogAuthenticationMiddleware.cs new file mode 100644 index 0000000..3eccf7c --- /dev/null +++ b/Owin.Security.Providers/Backlog/BacklogAuthenticationMiddleware.cs @@ -0,0 +1,88 @@ +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.Backlog +{ + public class BacklogAuthenticationMiddleware : AuthenticationMiddleware + { + private readonly HttpClient httpClient; + private readonly ILogger logger; + + public BacklogAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, + BacklogAuthenticationOptions 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")); + if (String.IsNullOrWhiteSpace(Options.ContractName)) + throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, + Resources.Exception_OptionMustBeProvided, "ContractName")); + + logger = app.CreateLogger(); + + if (Options.Provider == null) + Options.Provider = new BacklogAuthenticationProvider(); + + if (Options.StateDataFormat == null) + { + IDataProtector dataProtector = app.CreateDataProtector( + typeof (BacklogAuthenticationMiddleware).FullName, + Options.AuthenticationType, "v1"); + 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 + }; + } + + /// + /// Provides the object for processing + /// authentication-related requests. + /// + /// + /// An configured with the + /// supplied to the constructor. + /// + protected override AuthenticationHandler CreateHandler() + { + return new BacklogAuthenticationHandler(httpClient, logger); + } + + private HttpMessageHandler ResolveHttpMessageHandler(BacklogAuthenticationOptions 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/Backlog/BacklogAuthenticationOptions.cs b/Owin.Security.Providers/Backlog/BacklogAuthenticationOptions.cs new file mode 100644 index 0000000..beb27c1 --- /dev/null +++ b/Owin.Security.Providers/Backlog/BacklogAuthenticationOptions.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using Microsoft.Owin; +using Microsoft.Owin.Security; + +namespace Owin.Security.Providers.Backlog +{ + public class BacklogAuthenticationOptions : AuthenticationOptions + { + private const string TempTokenEndpoint = "https://contractname.backlog.jp/api/v2/oauth2/token"; + private const string TempUserInfoEndpoint = "https://contractname.backlog.jp/api/v2/users/myself"; + private const string TempAuthorizationEndpoint = "https://contractname.backlog.jp/OAuth2AccessRequest.action"; + + /// + /// Gets or sets the a pinned certificate validator to use to validate the endpoints used + /// in back channel communications belong to Google+. + /// + /// + /// 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 Google+. + /// 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 Google+. + /// + /// + /// 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 empty. + /// + 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 Google supplied Client ID + /// + public string ClientId { get; set; } + + /// + /// Gets or sets the Google supplied Client Secret + /// + public string ClientSecret { get; set; } + + /// + /// Gets or sets the ContractName for Backlog.It's also subdomain at the url of service.ex: https://contractName.backlog.jp/ + /// + public string ContractName { get; set; } + + + public string TokenEndpoint + { + get + { + var ub = new UriBuilder(TempTokenEndpoint); + ub.Host = ub.Host.Replace("contractname", this.ContractName); + + return ub.Uri.ToString(); + } + } + + public string UserInfoEndpoint + { + get + { + var ub = new UriBuilder(TempUserInfoEndpoint); + ub.Host = ub.Host.Replace("contractname", this.ContractName); + + return ub.Uri.ToString(); + } + } + + public string AuthorizationEndpoint + { + get + { + var ub = new UriBuilder(TempAuthorizationEndpoint); + ub.Host = ub.Host.Replace("contractname", this.ContractName); + + return ub.Uri.ToString(); + } + } + + /// + /// Gets or sets the used in the authentication events + /// + public IBacklogAuthenticationProvider Provider { 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 type used to secure data handled by the middleware. + /// + public ISecureDataFormat StateDataFormat { get; set; } + + /// + /// Initializes a new + /// + public BacklogAuthenticationOptions() + : base("Backlog") + { + Caption = Constants.DefaultAuthenticationType; + AuthenticationMode = AuthenticationMode.Passive; + BackchannelTimeout = TimeSpan.FromSeconds(60); + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/Backlog/Constants.cs b/Owin.Security.Providers/Backlog/Constants.cs new file mode 100644 index 0000000..9a86d7f --- /dev/null +++ b/Owin.Security.Providers/Backlog/Constants.cs @@ -0,0 +1,7 @@ +namespace Owin.Security.Providers.Backlog +{ + internal static class Constants + { + public const string DefaultAuthenticationType = "Backlog"; + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticatedContext.cs b/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticatedContext.cs new file mode 100644 index 0000000..828f95f --- /dev/null +++ b/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticatedContext.cs @@ -0,0 +1,105 @@ +// 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.Linq; +using System.Security.Claims; +using Microsoft.Owin; +using Microsoft.Owin.Security; +using Microsoft.Owin.Security.Provider; +using Newtonsoft.Json.Linq; + +namespace Owin.Security.Providers.Backlog +{ + /// + /// Contains information about the login session as well as the user . + /// + public class BacklogAuthenticatedContext : BaseContext + { + /// + /// Initializes a + /// + /// The OWIN environment + /// The JSON-serialized user + /// + /// Google+ Access token + /// Seconds until expiration + public BacklogAuthenticatedContext(IOwinContext context, JObject user, string accessToken, string expires, string refreshToken) + : base(context) + { + User = user; + AccessToken = accessToken; + RefreshToken = refreshToken; + + int expiresValue; + if (Int32.TryParse(expires, NumberStyles.Integer, CultureInfo.InvariantCulture, out expiresValue)) + { + ExpiresIn = TimeSpan.FromSeconds(expiresValue); + } + + Id = TryGetValue(user, "id"); + UserId = TryGetValue(user, "userId"); + Name = TryGetValue(user, "name"); + RoleType = TryGetValue(user, "roleType"); + Lang = TryGetValue(user, "lang"); + MailAddress = TryGetValue(user, "mailAddress"); + } + + /// + /// Gets the JSON-serialized user + /// + /// + /// Contains the Google user obtained from the endpoint https://www.googleapis.com/oauth2/v3/userinfo + /// + public JObject User { get; private set; } + + /// + /// Gets the Google OAuth access token + /// + public string AccessToken { get; private set; } + + /// + /// Gets the Google OAuth refresh token. This is only available when the RequestOfflineAccess property of is set to true + /// + public string RefreshToken { get; private set; } + + /// + /// Gets the Google+ access token expiration time + /// + public TimeSpan? ExpiresIn { get; set; } + + /// + /// Gets the Google+ user ID + /// + public string Id { get; private set; } + + public string UserId { get; private set; } + + /// + /// Gets the user's name + /// + public string Name { get; private set; } + + public string RoleType { get; private set; } + + public string Lang { get; private set; } + + public string MailAddress { 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; + } + } +} diff --git a/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticationProvider.cs b/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticationProvider.cs new file mode 100644 index 0000000..5dc6bf8 --- /dev/null +++ b/Owin.Security.Providers/Backlog/Provider/BacklogAuthenticationProvider.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; + +namespace Owin.Security.Providers.Backlog +{ + /// + /// Default implementation. + /// + public class BacklogAuthenticationProvider : IBacklogAuthenticationProvider + { + /// + /// Initializes a + /// + public BacklogAuthenticationProvider() + { + 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 Google+ succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + public virtual Task Authenticated(BacklogAuthenticatedContext 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(BacklogReturnEndpointContext context) + { + return OnReturnEndpoint(context); + } + } +} \ No newline at end of file diff --git a/Owin.Security.Providers/Backlog/Provider/BacklogReturnEndpointContext.cs b/Owin.Security.Providers/Backlog/Provider/BacklogReturnEndpointContext.cs new file mode 100644 index 0000000..059241d --- /dev/null +++ b/Owin.Security.Providers/Backlog/Provider/BacklogReturnEndpointContext.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.Backlog +{ + /// + /// Provides context information to middleware providers. + /// + public class BacklogReturnEndpointContext : ReturnEndpointContext + { + /// + /// + /// + /// OWIN environment + /// The authentication ticket + public BacklogReturnEndpointContext( + IOwinContext context, + AuthenticationTicket ticket) + : base(context, ticket) + { + } + } +} diff --git a/Owin.Security.Providers/Backlog/Provider/IGBacklogAuthenticationProvider.cs b/Owin.Security.Providers/Backlog/Provider/IGBacklogAuthenticationProvider.cs new file mode 100644 index 0000000..d38fce9 --- /dev/null +++ b/Owin.Security.Providers/Backlog/Provider/IGBacklogAuthenticationProvider.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; + +namespace Owin.Security.Providers.Backlog +{ + /// + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// + public interface IBacklogAuthenticationProvider + { + /// + /// Invoked whenever Google+ succesfully authenticates a user + /// + /// Contains information about the login session as well as the user . + /// A representing the completed operation. + Task Authenticated(BacklogAuthenticatedContext 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(BacklogReturnEndpointContext 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 5dacbd8..477f2f0 100644 --- a/Owin.Security.Providers/Owin.Security.Providers.csproj +++ b/Owin.Security.Providers/Owin.Security.Providers.csproj @@ -76,6 +76,15 @@ + + + + + + + + + diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index 9781535..38f622f 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -36,6 +36,7 @@ using Owin.Security.Providers.Untappd; using Owin.Security.Providers.Wargaming; using Owin.Security.Providers.WordPress; using Owin.Security.Providers.Yahoo; +using Owin.Security.Providers.Backlog; namespace OwinOAuthProvidersDemo { @@ -228,9 +229,9 @@ namespace OwinOAuthProvidersDemo //app.UseWargamingAccountAuthentication("", WargamingAuthenticationOptions.Region.NorthAmerica); //app.UseFlickrAuthentication("", ""); - //app.UseVisualStudioAuthentication( - // appId: "", - // appSecret: ""); + //app.UseVisualStudioAuthentication( + // appId: "", + // appSecret: ""); //app.UseSpotifyAuthentication( // clientId: "", @@ -256,6 +257,21 @@ namespace OwinOAuthProvidersDemo // ClientId = "", // ClientSecret = "" // }); + + //var options = new BacklogAuthenticationOptions + //{ + // ClientId = "", + // ClientSecret = "", + // ContractName = "", + // CallbackPath = new PathString(""), // ex.new PathString("/OauthTokenRequest") + // Provider = new BacklogAuthenticationProvider + // { + // OnAuthenticated = async context => await System.Threading.Tasks.Task.Run(()=> { System.Diagnostics.Debug.WriteLine(String.Format("Refresh Token: {0}", context.RefreshToken)); }) + // } + //}; + + //app.UseBacklogAuthentication(options); + } } }