diff --git a/Owin.Security.Providers/OnShape/Constants.cs b/Owin.Security.Providers/OnShape/Constants.cs index 799fc53..189cb10 100644 --- a/Owin.Security.Providers/OnShape/Constants.cs +++ b/Owin.Security.Providers/OnShape/Constants.cs @@ -1,7 +1,7 @@ -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { internal static class Constants { - public const string DefaultAuthenticationType = "OnShape"; + public const string DefaultAuthenticationType = "Onshape"; } } \ No newline at end of file diff --git a/Owin.Security.Providers/OnShape/OnShapeAuthenticationExtensions.cs b/Owin.Security.Providers/OnShape/OnShapeAuthenticationExtensions.cs index c915cba..b974d0b 100644 --- a/Owin.Security.Providers/OnShape/OnShapeAuthenticationExtensions.cs +++ b/Owin.Security.Providers/OnShape/OnShapeAuthenticationExtensions.cs @@ -1,25 +1,25 @@ using System; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { - public static class OnShapeAuthenticationExtensions + public static class OnshapeAuthenticationExtensions { - public static IAppBuilder UseOnShapeAuthentication(this IAppBuilder app, - OnShapeAuthenticationOptions options) + public static IAppBuilder UseOnshapeAuthentication(this IAppBuilder app, + OnshapeAuthenticationOptions options) { if (app == null) throw new ArgumentNullException("app"); if (options == null) throw new ArgumentNullException("options"); - app.Use(typeof(OnShapeAuthenticationMiddleware), app, options); + app.Use(typeof(OnshapeAuthenticationMiddleware), app, options); return app; } - public static IAppBuilder UseOnShapeAuthentication(this IAppBuilder app, string appKey, string appSecret) + public static IAppBuilder UseOnshapeAuthentication(this IAppBuilder app, string appKey, string appSecret) { - return app.UseOnShapeAuthentication(new OnShapeAuthenticationOptions + return app.UseOnshapeAuthentication(new OnshapeAuthenticationOptions { AppKey = appKey, AppSecret = appSecret diff --git a/Owin.Security.Providers/OnShape/OnShapeAuthenticationHandler.cs b/Owin.Security.Providers/OnShape/OnShapeAuthenticationHandler.cs index 85a65fa..fa7a64a 100644 --- a/Owin.Security.Providers/OnShape/OnShapeAuthenticationHandler.cs +++ b/Owin.Security.Providers/OnShape/OnShapeAuthenticationHandler.cs @@ -14,11 +14,11 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Net.Http.Headers; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { - public class OnShapeAuthenticationHandler : AuthenticationHandler + public class OnshapeAuthenticationHandler : AuthenticationHandler { - private const string StateCookie = "_OnShapeState"; + private const string StateCookie = "_OnshapeState"; private const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; private const string TokenEndpoint = "https://partner.dev.onshape.com/oauth/token"; private const string UserInfoEndpoint = "https://partner.dev.onshape.com/api/users/current"; @@ -26,7 +26,7 @@ namespace Owin.Security.Providers.OnShape private readonly ILogger logger; private readonly HttpClient httpClient; - public OnShapeAuthenticationHandler(HttpClient httpClient, ILogger logger) + public OnshapeAuthenticationHandler(HttpClient httpClient, ILogger logger) { this.httpClient = httpClient; this.logger = logger; @@ -76,6 +76,10 @@ namespace Owin.Security.Providers.OnShape body.Add(new KeyValuePair("client_id", Options.AppKey)); body.Add(new KeyValuePair("client_secret", Options.AppSecret)); + // Request the token + //HttpResponseMessage tokenResponse = + // await httpClient.PostAsync(TokenEndpoint, new FormUrlEncodedContent(body)); + // Get token var tokenRequest = new HttpRequestMessage(HttpMethod.Post, TokenEndpoint); tokenRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -90,6 +94,10 @@ namespace Owin.Security.Providers.OnShape dynamic response = JsonConvert.DeserializeObject(text); string accessToken = (string)response.access_token; + // Get the Onshape user + //HttpResponseMessage graphResponse = await httpClient.GetAsync( + // UserInfoEndpoint + "?access_token=" + Uri.EscapeDataString(accessToken), Request.CallCancelled); + string tokenType = (string)response.token_type; var userRequest = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint); @@ -102,7 +110,7 @@ namespace Owin.Security.Providers.OnShape text = await graphResponse.Content.ReadAsStringAsync(); JObject user = JObject.Parse(text); - var context = new OnShapeAuthenticatedContext(Context, user, accessToken); + var context = new OnshapeAuthenticatedContext(Context, user, accessToken); context.Identity = new ClaimsIdentity( Options.AuthenticationType, ClaimsIdentity.DefaultNameClaimType, @@ -202,7 +210,7 @@ namespace Owin.Security.Providers.OnShape return true; } - var context = new OnShapeReturnEndpointContext(Context, ticket); + var context = new OnshapeReturnEndpointContext(Context, ticket); context.SignInAsAuthenticationType = Options.SignInAsAuthenticationType; context.RedirectUri = ticket.Properties.RedirectUri; diff --git a/Owin.Security.Providers/OnShape/OnShapeAuthenticationMiddleware.cs b/Owin.Security.Providers/OnShape/OnShapeAuthenticationMiddleware.cs index ca2f053..9ab356d 100644 --- a/Owin.Security.Providers/OnShape/OnShapeAuthenticationMiddleware.cs +++ b/Owin.Security.Providers/OnShape/OnShapeAuthenticationMiddleware.cs @@ -8,15 +8,15 @@ using Microsoft.Owin.Security.DataHandler; using Microsoft.Owin.Security.DataProtection; using Microsoft.Owin.Security.Infrastructure; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { - public class OnShapeAuthenticationMiddleware : AuthenticationMiddleware + public class OnshapeAuthenticationMiddleware : AuthenticationMiddleware { private readonly HttpClient httpClient; private readonly ILogger logger; - public OnShapeAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, - OnShapeAuthenticationOptions options) + public OnshapeAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, + OnshapeAuthenticationOptions options) : base(next, options) { if (String.IsNullOrWhiteSpace(Options.AppKey)) @@ -24,15 +24,15 @@ namespace Owin.Security.Providers.OnShape if (String.IsNullOrWhiteSpace(Options.AppSecret)) throw new ArgumentException("AppSecret must be provided"); - logger = app.CreateLogger(); + logger = app.CreateLogger(); if (Options.Provider == null) - Options.Provider = new OnShapeAuthenticationProvider(); + Options.Provider = new OnshapeAuthenticationProvider(); if (Options.StateDataFormat == null) { IDataProtector dataProtector = app.CreateDataProtector( - typeof (OnShapeAuthenticationMiddleware).FullName, + typeof (OnshapeAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); } @@ -53,14 +53,14 @@ namespace Owin.Security.Providers.OnShape /// /// /// An configured with the - /// supplied to the constructor. + /// supplied to the constructor. /// - protected override AuthenticationHandler CreateHandler() + protected override AuthenticationHandler CreateHandler() { - return new OnShapeAuthenticationHandler(httpClient, logger); + return new OnshapeAuthenticationHandler(httpClient, logger); } - private HttpMessageHandler ResolveHttpMessageHandler(OnShapeAuthenticationOptions options) + private HttpMessageHandler ResolveHttpMessageHandler(OnshapeAuthenticationOptions options) { HttpMessageHandler handler = options.BackchannelHttpHandler ?? new WebRequestHandler(); diff --git a/Owin.Security.Providers/OnShape/OnShapeAuthenticationOptions.cs b/Owin.Security.Providers/OnShape/OnShapeAuthenticationOptions.cs index c67b3d7..5723e53 100644 --- a/Owin.Security.Providers/OnShape/OnShapeAuthenticationOptions.cs +++ b/Owin.Security.Providers/OnShape/OnShapeAuthenticationOptions.cs @@ -3,13 +3,13 @@ using System.Net.Http; using Microsoft.Owin; using Microsoft.Owin.Security; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { - public class OnShapeAuthenticationOptions : AuthenticationOptions + public class OnshapeAuthenticationOptions : AuthenticationOptions { /// /// Gets or sets the a pinned certificate validator to use to validate the endpoints used - /// in back channel communications belong to OnShape + /// in back channel communications belong to Onshape /// /// /// The pinned certificate validator. @@ -21,14 +21,14 @@ namespace Owin.Security.Providers.OnShape public ICertificateValidator BackchannelCertificateValidator { get; set; } /// - /// The HttpMessageHandler used to communicate with OnShape. + /// The HttpMessageHandler used to communicate with Onshape. /// 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 OnShape. + /// Gets or sets timeout value in milliseconds for back channel communications with Onshape. /// /// /// The back channel timeout in milliseconds. @@ -38,7 +38,7 @@ namespace Owin.Security.Providers.OnShape /// /// 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-OnShape". + /// Default value is "/signin-Onshape". /// public PathString CallbackPath { get; set; } @@ -52,19 +52,19 @@ namespace Owin.Security.Providers.OnShape } /// - /// Gets or sets the OnShape supplied Application Key + /// Gets or sets the Onshape supplied Application Key /// public string AppKey { get; set; } /// - /// Gets or sets the OnShape supplied Application Secret + /// Gets or sets the Onshape supplied Application Secret /// public string AppSecret { get; set; } /// - /// Gets or sets the used in the authentication events + /// Gets or sets the used in the authentication events /// - public IOnShapeAuthenticationProvider Provider { get; set; } + public IOnshapeAuthenticationProvider Provider { get; set; } /// /// Gets or sets the name of another authentication middleware which will be responsible for actually issuing a user @@ -78,10 +78,10 @@ namespace Owin.Security.Providers.OnShape public ISecureDataFormat StateDataFormat { get; set; } /// - /// Initializes a new + /// Initializes a new /// - public OnShapeAuthenticationOptions() - : base("OnShape") + public OnshapeAuthenticationOptions() + : base("Onshape") { Caption = Constants.DefaultAuthenticationType; CallbackPath = new PathString("/oauthRedirect"); diff --git a/Owin.Security.Providers/OnShape/Provider/IOnShapeAuthenticationProvider.cs b/Owin.Security.Providers/OnShape/Provider/IOnShapeAuthenticationProvider.cs index a919286..aa91db5 100644 --- a/Owin.Security.Providers/OnShape/Provider/IOnShapeAuthenticationProvider.cs +++ b/Owin.Security.Providers/OnShape/Provider/IOnShapeAuthenticationProvider.cs @@ -1,24 +1,24 @@ using System.Threading.Tasks; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { /// - /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> /// - public interface IOnShapeAuthenticationProvider + public interface IOnshapeAuthenticationProvider { /// - /// Invoked whenever OnShape successfully authenticates a user + /// Invoked whenever Onshape successfully authenticates a user /// /// Contains information about the login session as well as the user . /// A representing the completed operation. - Task Authenticated(OnShapeAuthenticatedContext context); + Task Authenticated(OnshapeAuthenticatedContext 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(OnShapeReturnEndpointContext context); + Task ReturnEndpoint(OnshapeReturnEndpointContext context); } } \ No newline at end of file diff --git a/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticatedContext.cs b/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticatedContext.cs index 746a584..a046187 100644 --- a/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticatedContext.cs +++ b/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticatedContext.cs @@ -8,20 +8,20 @@ using Microsoft.Owin.Security; using Microsoft.Owin.Security.Provider; using Newtonsoft.Json.Linq; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { /// /// Contains information about the login session as well as the user . /// - public class OnShapeAuthenticatedContext : BaseContext + public class OnshapeAuthenticatedContext : BaseContext { /// - /// Initializes a + /// Initializes a /// /// The OWIN environment /// The JSON-serialized user - /// OnShape Access token - public OnShapeAuthenticatedContext(IOwinContext context, JObject user, string accessToken) + /// Onshape Access token + public OnshapeAuthenticatedContext(IOwinContext context, JObject user, string accessToken) : base(context) { AccessToken = accessToken; @@ -35,17 +35,17 @@ namespace Owin.Security.Providers.OnShape /// Gets the JSON-serialized user /// /// - /// Contains the OnShape user obtained from the endpoint https://api.OnShape.com/1/account/info + /// Contains the Onshape user obtained from the endpoint https://api.Onshape.com/1/account/info /// public JObject User { get; private set; } /// - /// Gets the OnShape OAuth access token + /// Gets the Onshape OAuth access token /// public string AccessToken { get; private set; } /// - /// Gets the OnShape user ID + /// Gets the Onshape user ID /// public string Id { get; private set; } diff --git a/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticationProvider.cs b/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticationProvider.cs index c313e6e..bd25755 100644 --- a/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticationProvider.cs +++ b/Owin.Security.Providers/OnShape/Provider/OnShapeAuthenticationProvider.cs @@ -1,17 +1,17 @@ using System; using System.Threading.Tasks; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { /// - /// Default implementation. + /// Default implementation. /// - public class OnShapeAuthenticationProvider : IOnShapeAuthenticationProvider + public class OnshapeAuthenticationProvider : IOnshapeAuthenticationProvider { /// - /// Initializes a + /// Initializes a /// - public OnShapeAuthenticationProvider() + public OnshapeAuthenticationProvider() { OnAuthenticated = context => Task.FromResult(null); OnReturnEndpoint = context => Task.FromResult(null); @@ -20,19 +20,19 @@ namespace Owin.Security.Providers.OnShape /// /// Gets or sets the function that is invoked when the Authenticated method is invoked. /// - public Func OnAuthenticated { get; set; } + public Func OnAuthenticated { get; set; } /// /// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked. /// - public Func OnReturnEndpoint { get; set; } + public Func OnReturnEndpoint { get; set; } /// - /// Invoked whenever OnShape successfully authenticates a user + /// Invoked whenever Onshape successfully authenticates a user /// /// Contains information about the login session as well as the user . /// A representing the completed operation. - public virtual Task Authenticated(OnShapeAuthenticatedContext context) + public virtual Task Authenticated(OnshapeAuthenticatedContext context) { return OnAuthenticated(context); } @@ -42,7 +42,7 @@ namespace Owin.Security.Providers.OnShape /// /// /// A representing the completed operation. - public virtual Task ReturnEndpoint(OnShapeReturnEndpointContext context) + public virtual Task ReturnEndpoint(OnshapeReturnEndpointContext context) { return OnReturnEndpoint(context); } diff --git a/Owin.Security.Providers/OnShape/Provider/OnShapeReturnEndpointContext.cs b/Owin.Security.Providers/OnShape/Provider/OnShapeReturnEndpointContext.cs index 3829cfa..dd36bbb 100644 --- a/Owin.Security.Providers/OnShape/Provider/OnShapeReturnEndpointContext.cs +++ b/Owin.Security.Providers/OnShape/Provider/OnShapeReturnEndpointContext.cs @@ -4,19 +4,19 @@ using Microsoft.Owin; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Provider; -namespace Owin.Security.Providers.OnShape +namespace Owin.Security.Providers.Onshape { /// /// Provides context information to middleware providers. /// - public class OnShapeReturnEndpointContext : ReturnEndpointContext + public class OnshapeReturnEndpointContext : ReturnEndpointContext { /// /// /// /// OWIN environment /// The authentication ticket - public OnShapeReturnEndpointContext( + public OnshapeReturnEndpointContext( IOwinContext context, AuthenticationTicket ticket) : base(context, ticket) diff --git a/Owin.Security.Providers/Owin.Security.Providers.csproj b/Owin.Security.Providers/Owin.Security.Providers.csproj index 5b7122b..48525ef 100644 --- a/Owin.Security.Providers/Owin.Security.Providers.csproj +++ b/Owin.Security.Providers/Owin.Security.Providers.csproj @@ -223,15 +223,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index 94b70aa..c1da56d 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -40,7 +40,7 @@ using Owin.Security.Providers.Yahoo; using Owin.Security.Providers.Backlog; using Owin.Security.Providers.Vimeo; using Owin.Security.Providers.Fitbit; -using Owin.Security.Providers.OnShape; +using Owin.Security.Providers.Onshape; namespace OwinOAuthProvidersDemo { @@ -296,7 +296,7 @@ namespace OwinOAuthProvidersDemo // ClientSecret = "" //}); - //app.UseOnShapeAuthentication( + //app.UseOnshapeAuthentication( // appKey: "", // appSecret: ""); }