diff --git a/Owin.Security.Providers/Onshape/OnshapeAuthenticationExtensions.cs b/Owin.Security.Providers/Onshape/OnshapeAuthenticationExtensions.cs index d2168b6..edb0822 100644 --- a/Owin.Security.Providers/Onshape/OnshapeAuthenticationExtensions.cs +++ b/Owin.Security.Providers/Onshape/OnshapeAuthenticationExtensions.cs @@ -28,5 +28,17 @@ namespace Owin.Security.Providers.Onshape CallbackPath = new PathString(callbackPath) }); } + + public static IAppBuilder UseOnshapeAuthentication(this IAppBuilder app, string appKey, + string appSecret, string callbackPath, string hostname) + { + return app.UseOnshapeAuthentication(new OnshapeAuthenticationOptions + { + AppKey = appKey, + AppSecret = appSecret, + CallbackPath = new PathString(callbackPath), + Hostname = hostname + }); + } } } \ No newline at end of file diff --git a/Owin.Security.Providers/Onshape/OnshapeAuthenticationHandler.cs b/Owin.Security.Providers/Onshape/OnshapeAuthenticationHandler.cs index 1e3e0f4..9c80a60 100644 --- a/Owin.Security.Providers/Onshape/OnshapeAuthenticationHandler.cs +++ b/Owin.Security.Providers/Onshape/OnshapeAuthenticationHandler.cs @@ -20,8 +20,9 @@ namespace Owin.Security.Providers.Onshape { 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"; + private const string AuthorizationEndpoint = "/oauth/authorize"; + private const string TokenEndpoint = "/oauth/token"; + private const string UserInfoEndpoint = "/api/users/current"; private readonly ILogger logger; private readonly HttpClient httpClient; @@ -77,7 +78,7 @@ namespace Owin.Security.Providers.Onshape body.Add(new KeyValuePair("client_secret", Options.AppSecret)); // Get token - var tokenRequest = new HttpRequestMessage(HttpMethod.Post, TokenEndpoint); + var tokenRequest = new HttpRequestMessage(HttpMethod.Post, "https://" + Options.Hostname + TokenEndpoint); tokenRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); tokenRequest.Content = new FormUrlEncodedContent(body); @@ -92,7 +93,7 @@ namespace Owin.Security.Providers.Onshape string tokenType = (string)response.token_type; - var userRequest = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint); + var userRequest = new HttpRequestMessage(HttpMethod.Get, "https://" + Options.Hostname + UserInfoEndpoint); userRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); userRequest.Headers.Authorization = new AuthenticationHeaderValue(tokenType, accessToken); HttpResponseMessage graphResponse = await httpClient.SendAsync(userRequest, Request.CallCancelled); @@ -163,7 +164,7 @@ namespace Owin.Security.Providers.Onshape GenerateCorrelationId(properties); string authorizationEndpoint = - "https://partner.dev.onshape.com/oauth/authorize" + + "https://" + Options.Hostname + AuthorizationEndpoint + "?response_type=code" + "&client_id=" + Uri.EscapeDataString(Options.AppKey) + "&redirect_uri=" + Uri.EscapeDataString(redirectUri); diff --git a/Owin.Security.Providers/Onshape/OnshapeAuthenticationOptions.cs b/Owin.Security.Providers/Onshape/OnshapeAuthenticationOptions.cs index 487888b..03942ca 100644 --- a/Owin.Security.Providers/Onshape/OnshapeAuthenticationOptions.cs +++ b/Owin.Security.Providers/Onshape/OnshapeAuthenticationOptions.cs @@ -62,14 +62,9 @@ namespace Owin.Security.Providers.Onshape public string AppSecret { get; set; } /// - /// Endpoint which is used to redirect users to request Onshape access + /// Hostname to use for the endpoints. Override this for connecting to the partner stack. /// - public string AuthorizationEndpoint { get; set; } - - /// - /// Endpoint which is used to exchange code for access token - /// - public string TokenEndpoint { get; set; } + public string Hostname { get; set; } /// /// Gets or sets the used in the authentication events @@ -96,6 +91,7 @@ namespace Owin.Security.Providers.Onshape Caption = Constants.DefaultAuthenticationType; AuthenticationMode = AuthenticationMode.Passive; BackchannelTimeout = TimeSpan.FromSeconds(60); + Hostname = "cad.onshape.com"; } } } \ No newline at end of file diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index c1da56d..4dc6d73 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -298,7 +298,14 @@ namespace OwinOAuthProvidersDemo //app.UseOnshapeAuthentication( // appKey: "", - // appSecret: ""); + // appSecret: "", + // callbackPath: "/oauthRedirect"); + // + //app.UseOnshapeAuthentication( + // appKey: "", + // appSecret: "", + // callbackPath: "/oauthRedirect", + // hostname: "partner.dev.onshape.com"); } } }