{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Security/pulls/comments/22966537","id":22966537,"diff_hunk":"@@ -0,0 +1,173 @@\n+﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.ObjectModel;\n+using System.Diagnostics.CodeAnalysis;\n+using System.IdentityModel.Tokens;\n+using System.Net.Http;\n+using System.Text;\n+using Microsoft.AspNet.Builder;\n+using Microsoft.AspNet.Http;\n+using Microsoft.AspNet.Security.DataHandler;\n+using Microsoft.AspNet.Security.DataHandler.Encoder;\n+using Microsoft.AspNet.Security.DataHandler.Serializer;\n+using Microsoft.AspNet.Security.DataProtection;\n+using Microsoft.AspNet.Security.Infrastructure;\n+using Microsoft.Framework.Logging;\n+using Microsoft.Framework.OptionsModel;\n+using Microsoft.IdentityModel.Protocols;\n+\n+namespace Microsoft.AspNet.Security.OpenIdConnect\n+{\n+    /// <summary>\n+    /// ASP.NET middleware for obtaining identities using OpenIdConnect protocol.\n+    /// </summary>\n+    public class OpenIdConnectAuthenticationMiddleware : AuthenticationMiddleware<OpenIdConnectAuthenticationOptions>\n+    {\n+        private readonly ILogger _logger;\n+\n+        /// <summary>\n+        /// Initializes a <see cref=\"OpenIdConnectAuthenticationMiddleware\"/>\n+        /// </summary>\n+        /// <param name=\"next\">The next middleware in the ASP.NET pipeline to invoke</param>\n+        /// <param name=\"app\">The ASP.NET application</param>\n+        /// <param name=\"options\">Configuration options for the middleware</param>\n+        [SuppressMessage(\"Microsoft.Reliability\", \"CA2000:Dispose objects before losing scope\", Justification = \"Managed by caller\")]\n+        public OpenIdConnectAuthenticationMiddleware(\n+            RequestDelegate next,\n+            IServiceProvider services,\n+            IDataProtectionProvider dataProtectionProvider,\n+            ILoggerFactory loggerFactory,\n+            IOptions<ExternalAuthenticationOptions> externalOptions,\n+            IOptions<OpenIdConnectAuthenticationOptions> options,\n+            ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions)\n+            : base(next, services, options, configureOptions)\n+        {\n+            _logger = loggerFactory.Create<OpenIdConnectAuthenticationMiddleware>();\n+\n+            if (string.IsNullOrWhiteSpace(Options.TokenValidationParameters.AuthenticationType))\n+            {\n+                Options.TokenValidationParameters.AuthenticationType = externalOptions.Options.SignInAsAuthenticationType;\n+            }\n+\n+            if (Options.StateDataFormat == null)\n+            {\n+                var dataProtector = dataProtectionProvider.CreateDataProtector(\n+                    typeof(OpenIdConnectAuthenticationMiddleware).FullName, \n+\t\t\t\t\ttypeof(string).FullName,\n+                    Options.AuthenticationType,\n+\t\t\t\t\t\"v1\");\n+\n+                Options.StateDataFormat = new PropertiesDataFormat(dataProtector);\n+            }\n+\n+            if (Options.StringDataFormat == null)\n+            {\n+                var dataProtector = dataProtectionProvider.CreateDataProtector(\n+                    typeof(OpenIdConnectAuthenticationMiddleware).FullName,\n+                    typeof(string).FullName,\n+                    Options.AuthenticationType,\n+                    \"v1\");\n+\n+                Options.StringDataFormat = new SecureDataFormat<string>(new StringSerializer(), dataProtector, TextEncodings.Base64Url);","path":"src/Microsoft.AspNet.Security.OpenIDConnect/OpenIdConnectAuthenticationMiddleware.cs","position":72,"original_position":72,"commit_id":"b399dbdcd7e3391cd216ea69a0dcbaf1090dd311","original_commit_id":"b399dbdcd7e3391cd216ea69a0dcbaf1090dd311","user":{"login":"brentschmaltz","id":3172421,"avatar_url":"https://avatars.githubusercontent.com/u/3172421?v=3","gravatar_id":"","url":"https://api.github.com/users/brentschmaltz","html_url":"https://github.com/brentschmaltz","followers_url":"https://api.github.com/users/brentschmaltz/followers","following_url":"https://api.github.com/users/brentschmaltz/following{/other_user}","gists_url":"https://api.github.com/users/brentschmaltz/gists{/gist_id}","starred_url":"https://api.github.com/users/brentschmaltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brentschmaltz/subscriptions","organizations_url":"https://api.github.com/users/brentschmaltz/orgs","repos_url":"https://api.github.com/users/brentschmaltz/repos","events_url":"https://api.github.com/users/brentschmaltz/events{/privacy}","received_events_url":"https://api.github.com/users/brentschmaltz/received_events","type":"User","site_admin":false},"body":"I am planning to use it for the 'state' parameter.  Currently we wrap the 'state' inside an AuthenticationProperties structure. This add size and complications when fishing out specific items.","created_at":"2015-01-14T20:17:13Z","updated_at":"2015-01-14T20:17:13Z","html_url":"https://github.com/aspnet/Security/pull/112#discussion_r22966537","pull_request_url":"https://api.github.com/repos/aspnet/Security/pulls/112","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments/22966537"},"html":{"href":"https://github.com/aspnet/Security/pull/112#discussion_r22966537"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Security/pulls/112"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Security/pulls/112","id":27208966,"html_url":"https://github.com/aspnet/Security/pull/112","diff_url":"https://github.com/aspnet/Security/pull/112.diff","patch_url":"https://github.com/aspnet/Security/pull/112.patch","issue_url":"https://api.github.com/repos/aspnet/Security/issues/112","number":112,"state":"open","locked":false,"title":"Additions for OpenIdConnectMiddleware and OAuthBearer Beta1.","user":{"login":"brentschmaltz","id":3172421,"avatar_url":"https://avatars.githubusercontent.com/u/3172421?v=3","gravatar_id":"","url":"https://api.github.com/users/brentschmaltz","html_url":"https://github.com/brentschmaltz","followers_url":"https://api.github.com/users/brentschmaltz/followers","following_url":"https://api.github.com/users/brentschmaltz/following{/other_user}","gists_url":"https://api.github.com/users/brentschmaltz/gists{/gist_id}","starred_url":"https://api.github.com/users/brentschmaltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brentschmaltz/subscriptions","organizations_url":"https://api.github.com/users/brentschmaltz/orgs","repos_url":"https://api.github.com/users/brentschmaltz/repos","events_url":"https://api.github.com/users/brentschmaltz/events{/privacy}","received_events_url":"https://api.github.com/users/brentschmaltz/received_events","type":"User","site_admin":false},"body":"OpenIdConnect and OAuthBearer modifications.","created_at":"2015-01-12T17:03:26Z","updated_at":"2015-01-14T20:17:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89f50da63230bd8409d7008ba1ba4a4cd4e1396b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Security/pulls/112/commits","review_comments_url":"https://api.github.com/repos/aspnet/Security/pulls/112/comments","review_comment_url":"https://api.github.com/repos/aspnet/Security/pulls/comments/{number}","comments_url":"https://api.github.com/repos/aspnet/Security/issues/112/comments","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/b399dbdcd7e3391cd216ea69a0dcbaf1090dd311","head":{"label":"brentschmaltz:dev","ref":"dev","sha":"b399dbdcd7e3391cd216ea69a0dcbaf1090dd311","user":{"login":"brentschmaltz","id":3172421,"avatar_url":"https://avatars.githubusercontent.com/u/3172421?v=3","gravatar_id":"","url":"https://api.github.com/users/brentschmaltz","html_url":"https://github.com/brentschmaltz","followers_url":"https://api.github.com/users/brentschmaltz/followers","following_url":"https://api.github.com/users/brentschmaltz/following{/other_user}","gists_url":"https://api.github.com/users/brentschmaltz/gists{/gist_id}","starred_url":"https://api.github.com/users/brentschmaltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brentschmaltz/subscriptions","organizations_url":"https://api.github.com/users/brentschmaltz/orgs","repos_url":"https://api.github.com/users/brentschmaltz/repos","events_url":"https://api.github.com/users/brentschmaltz/events{/privacy}","received_events_url":"https://api.github.com/users/brentschmaltz/received_events","type":"User","site_admin":false},"repo":{"id":28565810,"name":"Security","full_name":"brentschmaltz/Security","owner":{"login":"brentschmaltz","id":3172421,"avatar_url":"https://avatars.githubusercontent.com/u/3172421?v=3","gravatar_id":"","url":"https://api.github.com/users/brentschmaltz","html_url":"https://github.com/brentschmaltz","followers_url":"https://api.github.com/users/brentschmaltz/followers","following_url":"https://api.github.com/users/brentschmaltz/following{/other_user}","gists_url":"https://api.github.com/users/brentschmaltz/gists{/gist_id}","starred_url":"https://api.github.com/users/brentschmaltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brentschmaltz/subscriptions","organizations_url":"https://api.github.com/users/brentschmaltz/orgs","repos_url":"https://api.github.com/users/brentschmaltz/repos","events_url":"https://api.github.com/users/brentschmaltz/events{/privacy}","received_events_url":"https://api.github.com/users/brentschmaltz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brentschmaltz/Security","description":"Middleware for security and authorization of web apps.","fork":true,"url":"https://api.github.com/repos/brentschmaltz/Security","forks_url":"https://api.github.com/repos/brentschmaltz/Security/forks","keys_url":"https://api.github.com/repos/brentschmaltz/Security/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brentschmaltz/Security/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brentschmaltz/Security/teams","hooks_url":"https://api.github.com/repos/brentschmaltz/Security/hooks","issue_events_url":"https://api.github.com/repos/brentschmaltz/Security/issues/events{/number}","events_url":"https://api.github.com/repos/brentschmaltz/Security/events","assignees_url":"https://api.github.com/repos/brentschmaltz/Security/assignees{/user}","branches_url":"https://api.github.com/repos/brentschmaltz/Security/branches{/branch}","tags_url":"https://api.github.com/repos/brentschmaltz/Security/tags","blobs_url":"https://api.github.com/repos/brentschmaltz/Security/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brentschmaltz/Security/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brentschmaltz/Security/git/refs{/sha}","trees_url":"https://api.github.com/repos/brentschmaltz/Security/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brentschmaltz/Security/statuses/{sha}","languages_url":"https://api.github.com/repos/brentschmaltz/Security/languages","stargazers_url":"https://api.github.com/repos/brentschmaltz/Security/stargazers","contributors_url":"https://api.github.com/repos/brentschmaltz/Security/contributors","subscribers_url":"https://api.github.com/repos/brentschmaltz/Security/subscribers","subscription_url":"https://api.github.com/repos/brentschmaltz/Security/subscription","commits_url":"https://api.github.com/repos/brentschmaltz/Security/commits{/sha}","git_commits_url":"https://api.github.com/repos/brentschmaltz/Security/git/commits{/sha}","comments_url":"https://api.github.com/repos/brentschmaltz/Security/comments{/number}","issue_comment_url":"https://api.github.com/repos/brentschmaltz/Security/issues/comments/{number}","contents_url":"https://api.github.com/repos/brentschmaltz/Security/contents/{+path}","compare_url":"https://api.github.com/repos/brentschmaltz/Security/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brentschmaltz/Security/merges","archive_url":"https://api.github.com/repos/brentschmaltz/Security/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brentschmaltz/Security/downloads","issues_url":"https://api.github.com/repos/brentschmaltz/Security/issues{/number}","pulls_url":"https://api.github.com/repos/brentschmaltz/Security/pulls{/number}","milestones_url":"https://api.github.com/repos/brentschmaltz/Security/milestones{/number}","notifications_url":"https://api.github.com/repos/brentschmaltz/Security/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brentschmaltz/Security/labels{/name}","releases_url":"https://api.github.com/repos/brentschmaltz/Security/releases{/id}","created_at":"2014-12-28T16:09:45Z","updated_at":"2015-01-14T19:37:01Z","pushed_at":"2015-01-14T19:37:01Z","git_url":"git://github.com/brentschmaltz/Security.git","ssh_url":"git@github.com:brentschmaltz/Security.git","clone_url":"https://github.com/brentschmaltz/Security.git","svn_url":"https://github.com/brentschmaltz/Security","homepage":"","size":689,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"fbe80ee64ee1e675f5b5e926c0c4afe858efdd9d","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":17723699,"name":"Security","full_name":"aspnet/Security","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Security","description":"Middleware for security and authorization of web apps.","fork":false,"url":"https://api.github.com/repos/aspnet/Security","forks_url":"https://api.github.com/repos/aspnet/Security/forks","keys_url":"https://api.github.com/repos/aspnet/Security/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Security/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Security/teams","hooks_url":"https://api.github.com/repos/aspnet/Security/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Security/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Security/events","assignees_url":"https://api.github.com/repos/aspnet/Security/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Security/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Security/tags","blobs_url":"https://api.github.com/repos/aspnet/Security/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Security/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Security/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Security/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Security/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Security/languages","stargazers_url":"https://api.github.com/repos/aspnet/Security/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Security/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Security/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Security/subscription","commits_url":"https://api.github.com/repos/aspnet/Security/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Security/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Security/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Security/issues/comments/{number}","contents_url":"https://api.github.com/repos/aspnet/Security/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Security/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Security/merges","archive_url":"https://api.github.com/repos/aspnet/Security/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Security/downloads","issues_url":"https://api.github.com/repos/aspnet/Security/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Security/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Security/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Security/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Security/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Security/releases{/id}","created_at":"2014-03-13T19:44:34Z","updated_at":"2015-01-08T02:10:52Z","pushed_at":"2015-01-13T23:24:30Z","git_url":"git://github.com/aspnet/Security.git","ssh_url":"git@github.com:aspnet/Security.git","clone_url":"https://github.com/aspnet/Security.git","svn_url":"https://github.com/aspnet/Security","homepage":"","size":1830,"stargazers_count":90,"watchers_count":90,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":34,"forks":30,"open_issues":34,"watchers":90,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Security/pulls/112"},"html":{"href":"https://github.com/aspnet/Security/pull/112"},"issue":{"href":"https://api.github.com/repos/aspnet/Security/issues/112"},"comments":{"href":"https://api.github.com/repos/aspnet/Security/issues/112/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Security/pulls/112/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Security/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Security/pulls/112/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Security/statuses/b399dbdcd7e3391cd216ea69a0dcbaf1090dd311"}}}}