diff --git a/source/Clients/Clients.sln b/source/Clients/Clients.sln index 712a89526..521c5cfb5 100644 --- a/source/Clients/Clients.sln +++ b/source/Clients/Clients.sln @@ -53,6 +53,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebForms OWIN Implicit", "W EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScript Client Manual", "JavaScriptImplicitClient Manual\JavaScript Client Manual.csproj", "{0109EFFE-B823-47C0-A27D-6DFD7B7169F2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample Web Api Using Pop", "SampleAspNetWebApiWithPop\Sample Web Api Using Pop.csproj", "{BB87949A-9B35-42D1-8805-799BAC60BBC5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -335,6 +337,22 @@ Global {0109EFFE-B823-47C0-A27D-6DFD7B7169F2}.Release|x64.Build.0 = Release|Any CPU {0109EFFE-B823-47C0-A27D-6DFD7B7169F2}.Release|x86.ActiveCfg = Release|Any CPU {0109EFFE-B823-47C0-A27D-6DFD7B7169F2}.Release|x86.Build.0 = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|ARM.ActiveCfg = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|ARM.Build.0 = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|x64.ActiveCfg = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|x64.Build.0 = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|x86.ActiveCfg = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Debug|x86.Build.0 = Debug|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|Any CPU.Build.0 = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|ARM.ActiveCfg = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|ARM.Build.0 = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|x64.ActiveCfg = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|x64.Build.0 = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|x86.ActiveCfg = Release|Any CPU + {BB87949A-9B35-42D1-8805-799BAC60BBC5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -342,5 +360,6 @@ Global GlobalSection(NestedProjects) = preSolution {C8CD1733-783A-4655-814B-9CF7FD7FDFE8} = {22C083F3-1F8A-4E90-B79C-13A6012492BC} {CFD6A3D6-02A2-4A7B-AF63-B9526A1F50E8} = {22C083F3-1F8A-4E90-B79C-13A6012492BC} + {BB87949A-9B35-42D1-8805-799BAC60BBC5} = {22C083F3-1F8A-4E90-B79C-13A6012492BC} EndGlobalSection EndGlobal diff --git a/source/Clients/Constants/Constants.cs b/source/Clients/Constants/Constants.cs index f5e271a33..0d8e29fa7 100644 --- a/source/Clients/Constants/Constants.cs +++ b/source/Clients/Constants/Constants.cs @@ -12,5 +12,6 @@ public static class Constants public const string TokenRevocationEndpoint = BaseAddress + "/connect/revocation"; public const string AspNetWebApiSampleApi = "http://localhost:2727/"; + public const string AspNetWebApiSampleApiUsingPoP = "http://localhost:46613/"; } } \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/App_Start/WebApiConfig.cs b/source/Clients/SampleAspNetWebApiWithPop/App_Start/WebApiConfig.cs new file mode 100644 index 000000000..b51929751 --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/App_Start/WebApiConfig.cs @@ -0,0 +1,25 @@ +using System.Web.Http; + +namespace SampleAspNetWebApiWithPop +{ + public static class WebApiConfig + { + public static HttpConfiguration Register() + { + // Web API configuration and services + var config = new HttpConfiguration(); + config.Formatters.Remove(config.Formatters.XmlFormatter); + + // Web API routes + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "{controller}", + defaults: new { id = RouteParameter.Optional } + ); + + return config; + } + } +} \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Controllers/IdentityController.cs b/source/Clients/SampleAspNetWebApiWithPop/Controllers/IdentityController.cs new file mode 100644 index 000000000..4cb19902b --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Controllers/IdentityController.cs @@ -0,0 +1,22 @@ +using System.Linq; +using System.Security.Claims; +using System.Web.Http; + +namespace SampleAspNetWebApiWithPop.Controllers +{ + [Authorize] + public class IdentityController : ApiController + { + public dynamic Get() + { + var principal = User as ClaimsPrincipal; + + return from c in principal.Identities.First().Claims + select new + { + c.Type, + c.Value + }; + } + } +} \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Controllers/TestController.cs b/source/Clients/SampleAspNetWebApiWithPop/Controllers/TestController.cs new file mode 100644 index 000000000..990326962 --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Controllers/TestController.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Web.Http; + +namespace SampleAspNetWebApiWithPop.Controllers +{ + public class TestController : ApiController + { + // GET api/ + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + } +} \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Properties/AssemblyInfo.cs b/source/Clients/SampleAspNetWebApiWithPop/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..38105148c --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SampleAspNetWebApiWithPop")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SampleAspNetWebApiWithPop")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bb87949a-9b35-42d1-8805-799bac60bbc5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/source/Clients/SampleAspNetWebApiWithPop/Sample Web Api Using Pop.csproj b/source/Clients/SampleAspNetWebApiWithPop/Sample Web Api Using Pop.csproj new file mode 100644 index 000000000..93eabf71c --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Sample Web Api Using Pop.csproj @@ -0,0 +1,193 @@ + + + + + + + Debug + AnyCPU + + + 2.0 + {BB87949A-9B35-42D1-8805-799BAC60BBC5} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + SampleAspNetWebApiWithPop + SampleAspNetWebApiWithPop + v4.5.2 + true + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\IdentityModel.1.9.2\lib\net45\IdentityModel.dll + True + + + ..\packages\IdentityModel.Owin.PopAuthentication.1.0.0-build00016\lib\net45\IdentityModel.Owin.PopAuthentication.dll + True + + + ..\packages\IdentityServer3.AccessTokenValidation.2.8.0\lib\net45\IdentityServer3.AccessTokenValidation.dll + True + + + ..\packages\jose-jwt.1.9.1\lib\4.0\jose-jwt.dll + True + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + True + + + + ..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll + True + + + ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll + True + + + ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + True + + + ..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll + True + + + ..\packages\Microsoft.Owin.Security.Jwt.3.0.1\lib\net45\Microsoft.Owin.Security.Jwt.dll + True + + + ..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll + True + + + ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + + ..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + + + + + + + + + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll + True + + + + + + + + + + + + + Web.config + + + Web.config + + + + + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 46613 + / + http://localhost:46613/ + False + False + + + False + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Startup.cs b/source/Clients/SampleAspNetWebApiWithPop/Startup.cs new file mode 100644 index 000000000..8b528c3de --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Startup.cs @@ -0,0 +1,48 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Owin; +using Owin; +using System.IdentityModel.Tokens; +using IdentityServer3.AccessTokenValidation; +using Microsoft.Owin.Security.OAuth; +using IdentityModel.Owin.PopAuthentication; + +[assembly: OwinStartup(typeof(SampleAspNetWebApiWithPop.Startup))] + +namespace SampleAspNetWebApiWithPop +{ + public class Startup + { + public void Configuration(IAppBuilder app) + { + JwtSecurityTokenHandler.InboundClaimTypeMap.Clear(); + + app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions + { + // we're looking for the PoP scheme, not Bearer + AuthenticationType = "PoP", + + Authority = "https://localhost:44333/core", + RequiredScopes = new[] { "write" }, + + // client credentials for the introspection endpoint + ClientId = "write", + ClientSecret = "secret", + + // this is used to extract the access token from the pop token + TokenProvider = new OAuthBearerAuthenticationProvider + { + OnRequestToken = async ctx => + { + ctx.Token = await DefaultPopTokenProvider.GetAccessTokenFromPopTokenAsync(ctx.OwinContext.Environment); + } + } + }); + + // this registers the middleware that does the signature validation of the request against the pop token secret + app.UseHttpSignatureValidation(); + + app.UseWebApi(WebApiConfig.Register()); + } + } +} diff --git a/source/Clients/SampleAspNetWebApiWithPop/Web.Debug.config b/source/Clients/SampleAspNetWebApiWithPop/Web.Debug.config new file mode 100644 index 000000000..2e302f9f9 --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Web.Release.config b/source/Clients/SampleAspNetWebApiWithPop/Web.Release.config new file mode 100644 index 000000000..c35844462 --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/Web.config b/source/Clients/SampleAspNetWebApiWithPop/Web.config new file mode 100644 index 000000000..7cb12903e --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/Web.config @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/Clients/SampleAspNetWebApiWithPop/packages.config b/source/Clients/SampleAspNetWebApiWithPop/packages.config new file mode 100644 index 000000000..76d80208e --- /dev/null +++ b/source/Clients/SampleAspNetWebApiWithPop/packages.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file