renaming the prefix from incorrect OnShape to the correct Onshape with only the O capitalized

This commit is contained in:
Tathagata Chakraborty
2015-09-15 09:35:41 +05:30
parent 6600badf92
commit f8217d9175
11 changed files with 85 additions and 77 deletions

View File

@@ -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";
}
}

View File

@@ -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

View File

@@ -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<OnShapeAuthenticationOptions>
public class OnshapeAuthenticationHandler : AuthenticationHandler<OnshapeAuthenticationOptions>
{
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<string, string>("client_id", Options.AppKey));
body.Add(new KeyValuePair<string, string>("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<dynamic>(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;

View File

@@ -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<OnShapeAuthenticationOptions>
public class OnshapeAuthenticationMiddleware : AuthenticationMiddleware<OnshapeAuthenticationOptions>
{
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<OnShapeAuthenticationMiddleware>();
logger = app.CreateLogger<OnshapeAuthenticationMiddleware>();
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
/// </summary>
/// <returns>
/// An <see cref="T:Microsoft.Owin.Security.Infrastructure.AuthenticationHandler" /> configured with the
/// <see cref="T:Owin.Security.Providers.OnShape.OnShapeAuthenticationOptions" /> supplied to the constructor.
/// <see cref="T:Owin.Security.Providers.Onshape.OnshapeAuthenticationOptions" /> supplied to the constructor.
/// </returns>
protected override AuthenticationHandler<OnShapeAuthenticationOptions> CreateHandler()
protected override AuthenticationHandler<OnshapeAuthenticationOptions> 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();

View File

@@ -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
{
/// <summary>
/// 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
/// </summary>
/// <value>
/// The pinned certificate validator.
@@ -21,14 +21,14 @@ namespace Owin.Security.Providers.OnShape
public ICertificateValidator BackchannelCertificateValidator { get; set; }
/// <summary>
/// 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.
/// </summary>
public HttpMessageHandler BackchannelHttpHandler { get; set; }
/// <summary>
/// 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.
/// </summary>
/// <value>
/// The back channel timeout in milliseconds.
@@ -38,7 +38,7 @@ namespace Owin.Security.Providers.OnShape
/// <summary>
/// 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".
/// </summary>
public PathString CallbackPath { get; set; }
@@ -52,19 +52,19 @@ namespace Owin.Security.Providers.OnShape
}
/// <summary>
/// Gets or sets the OnShape supplied Application Key
/// Gets or sets the Onshape supplied Application Key
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// Gets or sets the OnShape supplied Application Secret
/// Gets or sets the Onshape supplied Application Secret
/// </summary>
public string AppSecret { get; set; }
/// <summary>
/// Gets or sets the <see cref="IOnShapeAuthenticationProvider" /> used in the authentication events
/// Gets or sets the <see cref="IOnshapeAuthenticationProvider" /> used in the authentication events
/// </summary>
public IOnShapeAuthenticationProvider Provider { get; set; }
public IOnshapeAuthenticationProvider Provider { get; set; }
/// <summary>
/// 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<AuthenticationProperties> StateDataFormat { get; set; }
/// <summary>
/// Initializes a new <see cref="OnShapeAuthenticationOptions" />
/// Initializes a new <see cref="OnshapeAuthenticationOptions" />
/// </summary>
public OnShapeAuthenticationOptions()
: base("OnShape")
public OnshapeAuthenticationOptions()
: base("Onshape")
{
Caption = Constants.DefaultAuthenticationType;
CallbackPath = new PathString("/oauthRedirect");

View File

@@ -1,24 +1,24 @@
using System.Threading.Tasks;
namespace Owin.Security.Providers.OnShape
namespace Owin.Security.Providers.Onshape
{
/// <summary>
/// Specifies callback methods which the <see cref="OnShapeAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
/// Specifies callback methods which the <see cref="OnshapeAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
/// </summary>
public interface IOnShapeAuthenticationProvider
public interface IOnshapeAuthenticationProvider
{
/// <summary>
/// Invoked whenever OnShape successfully authenticates a user
/// Invoked whenever Onshape successfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
Task Authenticated(OnShapeAuthenticatedContext context);
Task Authenticated(OnshapeAuthenticatedContext context);
/// <summary>
/// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
Task ReturnEndpoint(OnShapeReturnEndpointContext context);
Task ReturnEndpoint(OnshapeReturnEndpointContext context);
}
}

View File

@@ -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
{
/// <summary>
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.
/// </summary>
public class OnShapeAuthenticatedContext : BaseContext
public class OnshapeAuthenticatedContext : BaseContext
{
/// <summary>
/// Initializes a <see cref="OnShapeAuthenticatedContext"/>
/// Initializes a <see cref="OnshapeAuthenticatedContext"/>
/// </summary>
/// <param name="context">The OWIN environment</param>
/// <param name="user">The JSON-serialized user</param>
/// <param name="accessToken">OnShape Access token</param>
public OnShapeAuthenticatedContext(IOwinContext context, JObject user, string accessToken)
/// <param name="accessToken">Onshape Access token</param>
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
/// </summary>
/// <remarks>
/// 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
/// </remarks>
public JObject User { get; private set; }
/// <summary>
/// Gets the OnShape OAuth access token
/// Gets the Onshape OAuth access token
/// </summary>
public string AccessToken { get; private set; }
/// <summary>
/// Gets the OnShape user ID
/// Gets the Onshape user ID
/// </summary>
public string Id { get; private set; }

View File

@@ -1,17 +1,17 @@
using System;
using System.Threading.Tasks;
namespace Owin.Security.Providers.OnShape
namespace Owin.Security.Providers.Onshape
{
/// <summary>
/// Default <see cref="IOnShapeAuthenticationProvider"/> implementation.
/// Default <see cref="IOnshapeAuthenticationProvider"/> implementation.
/// </summary>
public class OnShapeAuthenticationProvider : IOnShapeAuthenticationProvider
public class OnshapeAuthenticationProvider : IOnshapeAuthenticationProvider
{
/// <summary>
/// Initializes a <see cref="OnShapeAuthenticationProvider"/>
/// Initializes a <see cref="OnshapeAuthenticationProvider"/>
/// </summary>
public OnShapeAuthenticationProvider()
public OnshapeAuthenticationProvider()
{
OnAuthenticated = context => Task.FromResult<object>(null);
OnReturnEndpoint = context => Task.FromResult<object>(null);
@@ -20,19 +20,19 @@ namespace Owin.Security.Providers.OnShape
/// <summary>
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
/// </summary>
public Func<OnShapeAuthenticatedContext, Task> OnAuthenticated { get; set; }
public Func<OnshapeAuthenticatedContext, Task> OnAuthenticated { get; set; }
/// <summary>
/// Gets or sets the function that is invoked when the ReturnEndpoint method is invoked.
/// </summary>
public Func<OnShapeReturnEndpointContext, Task> OnReturnEndpoint { get; set; }
public Func<OnshapeReturnEndpointContext, Task> OnReturnEndpoint { get; set; }
/// <summary>
/// Invoked whenever OnShape successfully authenticates a user
/// Invoked whenever Onshape successfully authenticates a user
/// </summary>
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public virtual Task Authenticated(OnShapeAuthenticatedContext context)
public virtual Task Authenticated(OnshapeAuthenticatedContext context)
{
return OnAuthenticated(context);
}
@@ -42,7 +42,7 @@ namespace Owin.Security.Providers.OnShape
/// </summary>
/// <param name="context"></param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
public virtual Task ReturnEndpoint(OnShapeReturnEndpointContext context)
public virtual Task ReturnEndpoint(OnshapeReturnEndpointContext context)
{
return OnReturnEndpoint(context);
}

View File

@@ -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
{
/// <summary>
/// Provides context information to middleware providers.
/// </summary>
public class OnShapeReturnEndpointContext : ReturnEndpointContext
public class OnshapeReturnEndpointContext : ReturnEndpointContext
{
/// <summary>
///
/// </summary>
/// <param name="context">OWIN environment</param>
/// <param name="ticket">The authentication ticket</param>
public OnShapeReturnEndpointContext(
public OnshapeReturnEndpointContext(
IOwinContext context,
AuthenticationTicket ticket)
: base(context, ticket)

View File

@@ -223,15 +223,15 @@
<Compile Include="LinkedIn\Provider\LinkedInAuthenticationProvider.cs" />
<Compile Include="LinkedIn\Provider\LinkedInReturnEndpointContext.cs" />
<Compile Include="LinkedIn\Provider\ILinkedInAuthenticationProvider.cs" />
<Compile Include="OnShape\Constants.cs" />
<Compile Include="OnShape\OnShapeAuthenticationExtensions.cs" />
<Compile Include="OnShape\OnShapeAuthenticationHandler.cs" />
<Compile Include="OnShape\OnShapeAuthenticationMiddleware.cs" />
<Compile Include="OnShape\OnShapeAuthenticationOptions.cs" />
<Compile Include="OnShape\Provider\IOnShapeAuthenticationProvider.cs" />
<Compile Include="OnShape\Provider\OnShapeAuthenticatedContext.cs" />
<Compile Include="OnShape\Provider\OnShapeAuthenticationProvider.cs" />
<Compile Include="OnShape\Provider\OnShapeReturnEndpointContext.cs" />
<Compile Include="Onshape\Constants.cs" />
<Compile Include="Onshape\OnShapeAuthenticationExtensions.cs" />
<Compile Include="Onshape\OnShapeAuthenticationHandler.cs" />
<Compile Include="Onshape\OnShapeAuthenticationMiddleware.cs" />
<Compile Include="Onshape\OnShapeAuthenticationOptions.cs" />
<Compile Include="Onshape\Provider\IOnShapeAuthenticationProvider.cs" />
<Compile Include="Onshape\Provider\OnShapeAuthenticatedContext.cs" />
<Compile Include="Onshape\Provider\OnShapeAuthenticationProvider.cs" />
<Compile Include="Onshape\Provider\OnShapeReturnEndpointContext.cs" />
<Compile Include="OpenID\Constants.cs" />
<Compile Include="OpenID\Extensions\OpenIDSimpleRegistrationAuthenticationContextExtensions.cs" />
<Compile Include="OpenID\Extensions\OpenIDSimpleRegistrationExtension.cs" />

View File

@@ -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: "");
}