From 1e63b8335b78bf76d53b45945e5aeec78237f972 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 4 May 2016 18:29:39 -0400 Subject: [PATCH] fix up orcid a little --- .gitignore | 5 +- Gemfile.lock | 3 +- OwinOAuthProviders.sln | 12 +- .../App_Start/Startup.Auth.cs | 43 ++-- .../OwinOAuthProvidersDemo.csproj | 22 +- OwinOAuthProvidersDemo/Web.config | 21 +- OwinOAuthProvidersDemo/packages.config | 6 +- .../Message/OrcidMessageExtensions.cs | 40 ++-- .../OrcidAuthenticationOptions.cs | 202 +++++++++--------- .../Owin.Security.Providers.Orcid.csproj | 1 - .../Owin.Security.Providers.Orcid.nuspec | 29 --- 11 files changed, 180 insertions(+), 204 deletions(-) delete mode 100644 src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.nuspec diff --git a/.gitignore b/.gitignore index 12792ed..b3aafc2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,14 +11,15 @@ *.sln.docstates # Build results - +.gitignore/ +.bundle/ [Dd]ebug/ [Rr]elease/ x64/ build/ [Bb]in/ [Oo]bj/ - +OwinOAuthProvidersDemo/App_Data/ # Visual Studo 2015 cache/options directory .vs/ Owin.Security.Providers.nuspec diff --git a/Gemfile.lock b/Gemfile.lock index a65d7e6..71308d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,7 +21,6 @@ DEPENDENCIES albacore nokogiri os - rake BUNDLED WITH - 1.10.6 + 1.12.1 diff --git a/OwinOAuthProviders.sln b/OwinOAuthProviders.sln index 4b380e4..6141d54 100644 --- a/OwinOAuthProviders.sln +++ b/OwinOAuthProviders.sln @@ -2,8 +2,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OwinOAuthProvidersDemo", "OwinOAuthProvidersDemo\OwinOAuthProvidersDemo.csproj", "{5A438007-0C90-4DAC-BAA1-54A32164067F}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Owin.Security.Providers.ArcGISOnline", "src\Owin.Security.Providers.ArcGISOnline\Owin.Security.Providers.ArcGISOnline.csproj", "{8A49FAEF-D365-4D25-942C-1CAD03845A5E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Owin.Security.Providers.Asana", "src\Owin.Security.Providers.Asana\Owin.Security.Providers.Asana.csproj", "{F3E27220-1D8C-4037-94AA-7B7F4A12F351}" @@ -94,16 +92,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Owin.Security.Providers.Sla EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Owin.Security.Providers.Orcid", "src\Owin.Security.Providers.Orcid\Owin.Security.Providers.Orcid.csproj", "{89CB4342-E23D-4E7C-89E5-C369599A5860}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OwinOAuthProvidersDemo", "OwinOAuthProvidersDemo\OwinOAuthProvidersDemo.csproj", "{5A438007-0C90-4DAC-BAA1-54A32164067F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5A438007-0C90-4DAC-BAA1-54A32164067F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5A438007-0C90-4DAC-BAA1-54A32164067F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5A438007-0C90-4DAC-BAA1-54A32164067F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5A438007-0C90-4DAC-BAA1-54A32164067F}.Release|Any CPU.Build.0 = Release|Any CPU {8A49FAEF-D365-4D25-942C-1CAD03845A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8A49FAEF-D365-4D25-942C-1CAD03845A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A49FAEF-D365-4D25-942C-1CAD03845A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -284,6 +280,10 @@ Global {89CB4342-E23D-4E7C-89E5-C369599A5860}.Debug|Any CPU.Build.0 = Debug|Any CPU {89CB4342-E23D-4E7C-89E5-C369599A5860}.Release|Any CPU.ActiveCfg = Release|Any CPU {89CB4342-E23D-4E7C-89E5-C369599A5860}.Release|Any CPU.Build.0 = Release|Any CPU + {5A438007-0C90-4DAC-BAA1-54A32164067F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A438007-0C90-4DAC-BAA1-54A32164067F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A438007-0C90-4DAC-BAA1-54A32164067F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A438007-0C90-4DAC-BAA1-54A32164067F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index a6f3847..dd040c8 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -3,21 +3,23 @@ using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; +//using Owin.Security.Providers.Orcid; + namespace OwinOAuthProvidersDemo { - public partial class Startup - { - // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 - public void ConfigureAuth(IAppBuilder app) - { - // Enable the application to use a cookie to store information for the signed in user - app.UseCookieAuthentication(new CookieAuthenticationOptions - { - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, - LoginPath = new PathString("/Account/Login") - }); - // Use a cookie to temporarily store information about a user logging in with a third party login provider - app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); + public partial class Startup + { + // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 + public void ConfigureAuth(IAppBuilder app) + { + // Enable the application to use a cookie to store information for the signed in user + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, + LoginPath = new PathString("/Account/Login") + }); + // Use a cookie to temporarily store information about a user logging in with a third party login provider + app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); //app.UseDeviantArtAuthentication("id", "secret"); //app.UseUntappdAuthentication("id", "secret"); // Uncomment the following lines to enable logging in with third party login providers @@ -71,8 +73,8 @@ namespace OwinOAuthProvidersDemo /* * Twitch sign-ins use /signin-Twitch as the URL for authentication - * - + * + */ ////Simple Twitch Sign-in @@ -85,7 +87,6 @@ namespace OwinOAuthProvidersDemo // ClientSecret = "", // Provider = new TwitchAuthenticationProvider() // { - // OnAuthenticated = async z => // { //// Getting the twitch users picture @@ -108,8 +109,6 @@ namespace OwinOAuthProvidersDemo //}; //app.UseTwitchAuthentication(opt); - - //app.UseOpenIDAuthentication("http://me.yahoo.com/", "Yahoo"); //app.UseOpenIDAuthentication("https://openid.stackexchange.com/", "StackExchange"); @@ -123,7 +122,7 @@ namespace OwinOAuthProvidersDemo //app.UseOpenIDAuthentication("http://openid.orange.fr/server", "Orange", true); //app.UseSalesforceAuthentication( - // clientId: "", + // clientId: "", // clientSecret: ""); //in scenarios where a sandbox URL needs to be used @@ -275,8 +274,8 @@ namespace OwinOAuthProvidersDemo //app.UseXingAuthentication("", ""); //app.UseDoYouBuzzAuthentication("", ""); - - //app.UseOrcidAuthentication("", ""); + //app.("", ""); + //app.UseOrcidAuthentication("APP-QQ4XO1AYU3WR696B", "6bb22d2e-71b3-4d5d-b1af-f5d3a8cd4270"); } } -} +} \ No newline at end of file diff --git a/OwinOAuthProvidersDemo/OwinOAuthProvidersDemo.csproj b/OwinOAuthProvidersDemo/OwinOAuthProvidersDemo.csproj index bbaaf3f..2d2c708 100644 --- a/OwinOAuthProvidersDemo/OwinOAuthProvidersDemo.csproj +++ b/OwinOAuthProvidersDemo/OwinOAuthProvidersDemo.csproj @@ -13,7 +13,7 @@ Properties OwinOAuthProvidersDemo OwinOAuthProvidersDemo - v4.5 + v4.5.2 false true 44300 @@ -21,6 +21,7 @@ disabled false + true @@ -65,16 +66,16 @@ True - - ..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll + + ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll True ..\packages\Microsoft.Owin.Host.SystemWeb.2.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll True - - ..\packages\Microsoft.Owin.Security.2.1.0\lib\net45\Microsoft.Owin.Security.dll + + ..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll True @@ -105,8 +106,8 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True - - ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True @@ -115,13 +116,13 @@ + - - + ..\packages\Microsoft.AspNet.WebPages.3.2.0\lib\net45\System.Web.Helpers.dll True @@ -150,9 +151,7 @@ ..\packages\Microsoft.AspNet.WebPages.3.2.0\lib\net45\System.Web.WebPages.Razor.dll True - - @@ -163,6 +162,7 @@ + ..\packages\WebGrease.1.6.0\lib\WebGrease.dll True diff --git a/OwinOAuthProvidersDemo/Web.config b/OwinOAuthProvidersDemo/Web.config index dc9e98f..0f5f4a7 100644 --- a/OwinOAuthProvidersDemo/Web.config +++ b/OwinOAuthProvidersDemo/Web.config @@ -1,16 +1,15 @@ - + -
- + @@ -18,9 +17,17 @@ + - + @@ -40,11 +47,11 @@ - + - + @@ -60,7 +67,7 @@ - + diff --git a/OwinOAuthProvidersDemo/packages.config b/OwinOAuthProvidersDemo/packages.config index d4b92b5..54ead64 100644 --- a/OwinOAuthProvidersDemo/packages.config +++ b/OwinOAuthProvidersDemo/packages.config @@ -13,9 +13,9 @@ - + - + @@ -24,7 +24,7 @@ - + diff --git a/src/Owin.Security.Providers.Orcid/Message/OrcidMessageExtensions.cs b/src/Owin.Security.Providers.Orcid/Message/OrcidMessageExtensions.cs index b0e280c..467a539 100644 --- a/src/Owin.Security.Providers.Orcid/Message/OrcidMessageExtensions.cs +++ b/src/Owin.Security.Providers.Orcid/Message/OrcidMessageExtensions.cs @@ -1,35 +1,35 @@ -using System; +using Microsoft.Owin; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.Owin; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Owin.Security.Providers.Orcid.Message { - public static class OrcidMessageExtensions - { - public static OrcidAuthenticatedContext ToAuthenticationContext(this string json, IOwinContext context, string orcid, string accessToken) - { - var profile = JsonConvert.DeserializeObject(json); + public static class OrcidMessageExtensions + { + public static OrcidAuthenticatedContext ToAuthenticationContext(this string json, IOwinContext context, string orcid, string accessToken) + { + var profile = JsonConvert.DeserializeObject(json); - var user = JObject.Parse(json); + var user = JObject.Parse(json); - var authenticatedContext = new OrcidAuthenticatedContext(context, user, accessToken); + var authenticatedContext = new OrcidAuthenticatedContext(context, user, accessToken); - var email = profile.OrcidProfile.OrcidBio.ContactDetails.Email.LastOrDefault(); - if (email != null) - authenticatedContext.Email = email.Value; + var email = profile.OrcidProfile.OrcidBio?.ContactDetails?.Email?.LastOrDefault(); + if(email != null) + authenticatedContext.Email = email.Value; authenticatedContext.Id = orcid; authenticatedContext.UserName = orcid; - authenticatedContext.FirstName = profile.OrcidProfile.OrcidBio.PersonalDetails.GivenNames.Value; - authenticatedContext.LastName = profile.OrcidProfile.OrcidBio.PersonalDetails.FamilyName.Value; + authenticatedContext.FirstName = profile.OrcidProfile.OrcidBio.PersonalDetails.GivenNames.Value; + authenticatedContext.LastName = profile.OrcidProfile.OrcidBio.PersonalDetails.FamilyName.Value; - return authenticatedContext; - } - } -} + return authenticatedContext; + } + } +} \ No newline at end of file diff --git a/src/Owin.Security.Providers.Orcid/OrcidAuthenticationOptions.cs b/src/Owin.Security.Providers.Orcid/OrcidAuthenticationOptions.cs index 5c10cbb..126a7a6 100644 --- a/src/Owin.Security.Providers.Orcid/OrcidAuthenticationOptions.cs +++ b/src/Owin.Security.Providers.Orcid/OrcidAuthenticationOptions.cs @@ -1,120 +1,120 @@ -using System; +using Microsoft.Owin; +using Microsoft.Owin.Security; +using System; using System.Collections.Generic; using System.Net.Http; -using Microsoft.Owin; -using Microsoft.Owin.Security; namespace Owin.Security.Providers.Orcid { - public class OrcidAuthenticationOptions : AuthenticationOptions - { - /// - /// Gets or sets the a pinned certificate validator to use to validate the endpoints used - /// in back channel communications belong to Orcid. - /// - /// - /// 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; } + public class OrcidAuthenticationOptions : AuthenticationOptions + { + /// + /// Gets or sets the a pinned certificate validator to use to validate the endpoints used + /// in back channel communications belong to Orcid. + /// + /// + /// 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 Orcid. - /// This cannot be set at the same time as BackchannelCertificateValidator unless the value - /// can be downcast to a WebRequestHandler. - /// - public HttpMessageHandler BackchannelHttpHandler { get; set; } + /// + /// The HttpMessageHandler used to communicate with Orcid. + /// 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 Orcid. - /// - /// - /// The back channel timeout in milliseconds. - /// - public TimeSpan BackchannelTimeout { get; set; } + /// + /// Gets or sets timeout value in milliseconds for back channel communications with Orcid. + /// + /// + /// 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-Orcid". - /// - public PathString CallbackPath { 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-orcid". + /// + 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; } - } + /// + /// 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 Orcid supplied Client ID - /// - public string ClientId { get; set; } + /// + /// Gets or sets the Orcid supplied Client ID + /// + public string ClientId { get; set; } - /// - /// Gets or sets the Orcid supplied Client Secret - /// - public string ClientSecret { get; set; } + /// + /// Gets or sets the Orcid supplied Client Secret + /// + public string ClientSecret { get; set; } - /// - /// Gets the sets of OAuth endpoints used to authenticate against Orcid. Overriding these endpoints allows you to use Orcid Enterprise for - /// authentication. - /// - public OrcidAuthenticationEndpoints Endpoints { get; set; } + /// + /// Gets the sets of OAuth endpoints used to authenticate against Orcid. Overriding these endpoints allows you to use Orcid Enterprise for + /// authentication. + /// + public OrcidAuthenticationEndpoints Endpoints { get; set; } - /// - /// Gets or sets the used in the authentication events - /// - public IOrcidAuthenticationProvider Provider { get; set; } + /// + /// Gets or sets the used in the authentication events + /// + public IOrcidAuthenticationProvider Provider { get; set; } - /// - /// A list of permissions to request. - /// - public IList Scope { get; private set; } + /// + /// A list of permissions to request. + /// + public IList Scope { get; private set; } - /// - /// Specifies how the authorization server prompts the user for reauthentication and reapproval. This parameter is optional. - /// The only values Orcid supports are: - /// login—The authorization server must prompt the user for reauthentication, forcing the user to log in again. - /// consent—The authorization server must prompt the user for reapproval before returning information to the client. - /// It is valid to pass both values, separated by a space, to require the user to both log in and reauthorize. - /// - public string Prompt { get; set; } + /// + /// Specifies how the authorization server prompts the user for reauthentication and reapproval. This parameter is optional. + /// The only values Orcid supports are: + /// login—The authorization server must prompt the user for reauthentication, forcing the user to log in again. + /// consent—The authorization server must prompt the user for reapproval before returning information to the client. + /// It is valid to pass both values, separated by a space, to require the user to both log in and reauthorize. + /// + public string Prompt { 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 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; } + /// + /// Gets or sets the type used to secure data handled by the middleware. + /// + public ISecureDataFormat StateDataFormat { get; set; } - /// - /// Initializes a new - /// - public OrcidAuthenticationOptions() - : base("Orcid") - { - Caption = Constants.DefaultAuthenticationType; - CallbackPath = new PathString("/signin-orcid"); - AuthenticationMode = AuthenticationMode.Passive; - Scope = new List(); - BackchannelTimeout = TimeSpan.FromSeconds(60); - Endpoints = new OrcidAuthenticationEndpoints - { - AuthorizationEndpoint = OrcidAuthenticationEndpoints.Default.AuthorizationEndPoint, - TokenEndpoint = OrcidAuthenticationEndpoints.Default.TokenEndpoint, - ApiEndpoint = OrcidAuthenticationEndpoints.Default.ApiEndpoint - }; - } - } + /// + /// Initializes a new + /// + public OrcidAuthenticationOptions() + : base("Orcid") + { + Caption = Constants.DefaultAuthenticationType; + CallbackPath = new PathString("/signin-orcid"); + AuthenticationMode = AuthenticationMode.Passive; + Scope = new List(); + BackchannelTimeout = TimeSpan.FromSeconds(60); + Endpoints = new OrcidAuthenticationEndpoints + { + AuthorizationEndpoint = OrcidAuthenticationEndpoints.Default.AuthorizationEndPoint, + TokenEndpoint = OrcidAuthenticationEndpoints.Default.TokenEndpoint, + ApiEndpoint = OrcidAuthenticationEndpoints.Default.ApiEndpoint + }; + } + } } \ No newline at end of file diff --git a/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.csproj b/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.csproj index fac17cc..bfcc773 100644 --- a/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.csproj +++ b/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.csproj @@ -73,7 +73,6 @@ - diff --git a/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.nuspec b/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.nuspec deleted file mode 100644 index e9d9eb5..0000000 --- a/src/Owin.Security.Providers.Orcid/Owin.Security.Providers.Orcid.nuspec +++ /dev/null @@ -1,29 +0,0 @@ - - - - Owin.Security.Providers.Orcid - 1.0.0 - Rick Zakharov - RickZee - http://opensource.org/licenses/MIT - https://github.com/RickZee/OwinOAuthProviders - false - - Adds ORCID OAuth provider for OWIN to use with ASP.NET - - - Providers have now been split into their own packages from Owin.Security.Providers - - - - Copyright 2016 - owin katana oauth LinkedIn - - - - - - - - -