diff options
9 files changed, 46 insertions, 27 deletions
diff --git a/samples/OpenIdRelyingPartyWebFormsVB/Global.asax.vb b/samples/OpenIdRelyingPartyWebFormsVB/Global.asax.vb index 257e11a..97b0d51 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/Global.asax.vb +++ b/samples/OpenIdRelyingPartyWebFormsVB/Global.asax.vb @@ -4,7 +4,6 @@ Imports System.Configuration Imports System.IO Imports System.Text Imports System.Web -Imports DotNetOpenAuth.ApplicationBlock Imports OpenIdRelyingPartyWebFormsVB Public Class Global_asax diff --git a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx index 7f1fa0e..becc9a0 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx +++ b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx @@ -1,4 +1,4 @@ -<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="loginProgrammatic.aspx.vb" +<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="loginProgrammatic.aspx.vb" Async="true" Inherits="OpenIdRelyingPartyWebFormsVB.LoginProgrammatic" MasterPageFile="~/Site.Master" %> <asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Main"> <h2>Login Page </h2> diff --git a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.designer.vb b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.designer.vb index 907fcda..e747a88 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.designer.vb +++ b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.designer.vb @@ -1,10 +1,9 @@ '------------------------------------------------------------------------------ ' <auto-generated> ' This code was generated by a tool. -' Runtime Version:2.0.50727.4927 ' ' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. +' the code is regenerated. ' </auto-generated> '------------------------------------------------------------------------------ @@ -12,7 +11,6 @@ Option Strict On Option Explicit On - Partial Public Class LoginProgrammatic '''<summary> diff --git a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.vb b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.vb index 6cac182..537fd96 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.vb +++ b/samples/OpenIdRelyingPartyWebFormsVB/LoginProgrammatic.aspx.vb @@ -1,4 +1,5 @@ Imports System.Net +Imports System.Threading Imports System.Web.Security Imports DotNetOpenAuth.Messaging Imports DotNetOpenAuth.OpenId @@ -15,13 +16,13 @@ Public Class LoginProgrammatic args.IsValid = Identifier.IsValid(args.Value) End Sub - Protected Sub loginButton_Click(ByVal sender As Object, ByVal e As EventArgs) + Protected Async Sub loginButton_Click(ByVal sender As Object, ByVal e As EventArgs) If Not Me.Page.IsValid Then Return ' don't login if custom validation failed. End If Try - Dim request As IAuthenticationRequest = relyingParty.CreateRequest(Me.openIdBox.Text) + Dim request As IAuthenticationRequest = Await relyingParty.CreateRequestAsync(Me.openIdBox.Text) ' This is where you would add any OpenID extensions you wanted ' to include in the authentication request. request.AddExtension(New ClaimsRequest() With { _ @@ -32,7 +33,7 @@ Public Class LoginProgrammatic .TimeZone = DemandLevel.Require _ }) ' Send your visitor to their Provider for authentication. - request.RedirectToProvider() + Await request.RedirectToProviderAsync() Catch ex As ProtocolException ' The user probably entered an Identifier that ' was not a valid OpenID endpoint. @@ -41,7 +42,7 @@ Public Class LoginProgrammatic End Try End Sub - Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load + Protected Async Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Me.openIdBox.Focus() ' For debugging/testing, we allow remote clearing of all associations... ' NOT a good idea on a production site. @@ -53,7 +54,7 @@ Public Class LoginProgrammatic builder.Query = Nothing Me.Response.Redirect(builder.Uri.AbsoluteUri) End If - Dim response As IAuthenticationResponse = relyingParty.GetResponse + Dim response As IAuthenticationResponse = Await relyingParty.GetResponseAsync(CancellationToken.None) If response IsNot Nothing Then Select Case response.Status Case AuthenticationStatus.Authenticated diff --git a/samples/OpenIdRelyingPartyWebFormsVB/OpenIdRelyingPartyWebFormsVB.vbproj b/samples/OpenIdRelyingPartyWebFormsVB/OpenIdRelyingPartyWebFormsVB.vbproj index c044f4c..75d0490 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/OpenIdRelyingPartyWebFormsVB.vbproj +++ b/samples/OpenIdRelyingPartyWebFormsVB/OpenIdRelyingPartyWebFormsVB.vbproj @@ -64,6 +64,8 @@ <Reference Include="System.Data" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Drawing" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Net.Http.WebRequest" /> <Reference Include="System.Web.ApplicationServices" /> <Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.Entity" /> @@ -216,10 +218,6 @@ <Project>{3896A32A-E876-4C23-B9B8-78E17D134CD3}</Project> <Name>DotNetOpenAuth.OpenId</Name> </ProjectReference> - <ProjectReference Include="..\DotNetOpenAuth.ApplicationBlock\DotNetOpenAuth.ApplicationBlock.csproj"> - <Project>{AA78D112-D889-414B-A7D4-467B34C7B663}</Project> - <Name>DotNetOpenAuth.ApplicationBlock</Name> - </ProjectReference> </ItemGroup> <ItemGroup> <Folder Include="App_Data\" /> diff --git a/samples/OpenIdRelyingPartyWebFormsVB/Web.config b/samples/OpenIdRelyingPartyWebFormsVB/Web.config index b849324..a9929c2 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/Web.config +++ b/samples/OpenIdRelyingPartyWebFormsVB/Web.config @@ -66,18 +66,20 @@ <!-- Google sign-up: https://www.google.com/accounts/ManageDomains --> <add key="googleConsumerKey" value="demo.dotnetopenauth.net"/> <add key="googleConsumerSecret" value="5Yv1TfKm1551QrXZ9GpqepeD"/> + <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings> <system.web> + <httpRuntime targetFramework="4.5" /> <!--<sessionState cookieless="true" />--> - <compilation debug="true" targetFramework="4.0"> + <compilation debug="true" targetFramework="4.5"> <assemblies> <remove assembly="DotNetOpenAuth.Contracts"/> </assemblies> </compilation> <customErrors mode="RemoteOnly"/> <authentication mode="Forms"> - <forms name="OpenIdRelyingPartyVBSession"/> <!-- named cookie prevents conflicts with other samples --> + <forms name="OpenIdRelyingPartyVBSession" loginUrl="loginProgrammatic.aspx"/> <!-- named cookie prevents conflicts with other samples --> </authentication> <trace enabled="false" writeToDiagnosticsTrace="true" /> <!-- Trust level discussion: diff --git a/samples/OpenIdRelyingPartyWebFormsVB/packages.config b/samples/OpenIdRelyingPartyWebFormsVB/packages.config index 6562527..8e40260 100644 --- a/samples/OpenIdRelyingPartyWebFormsVB/packages.config +++ b/samples/OpenIdRelyingPartyWebFormsVB/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="log4net" version="2.0.0" targetFramework="net45" /> + <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 4f4eb66..2aee6ea 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -383,6 +383,24 @@ namespace DotNetOpenAuth.Messaging { return new HttpResponseMessageActionResult(response); } + public static void Send(this HttpResponseMessage response, HttpContextBase context = null) { + Requires.NotNull(response, "response"); + context = context ?? new HttpContextWrapper(HttpContext.Current); + Verify.Operation(context != null, MessagingStrings.HttpContextRequired); + + context.Response.StatusCode = (int)response.StatusCode; + context.Response.StatusDescription = response.ReasonPhrase; + foreach (var header in response.Headers) { + foreach (var value in header.Value) { + context.Response.AddHeader(header.Key, value); + } + } + + if (response.Content != null) { + response.Content.CopyToAsync(context.Response.OutputStream).Wait(); + } + } + internal static void DisposeIfNotNull(this IDisposable disposable) { if (disposable != null) { disposable.Dispose(); @@ -1977,17 +1995,7 @@ namespace DotNetOpenAuth.Messaging { } public override void ExecuteResult(ControllerContext context) { - context.HttpContext.Response.StatusCode = (int)this.response.StatusCode; - context.HttpContext.Response.StatusDescription = this.response.ReasonPhrase; - foreach (var header in this.response.Headers) { - foreach (var value in header.Value) { - context.HttpContext.Response.AddHeader(header.Key, value); - } - } - - if (this.response.Content != null) { - this.response.Content.CopyToAsync(context.HttpContext.Response.OutputStream).Wait(); - } + this.response.Send(context.HttpContext); } } } diff --git a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs index f8d542d..b656150 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/OpenIdUtilities.cs @@ -15,12 +15,15 @@ namespace DotNetOpenAuth.OpenId { using System.Net.Cache; using System.Net.Http; using System.Text.RegularExpressions; + using System.Threading; using System.Threading.Tasks; using System.Web; using System.Web.UI; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Extensions; + using DotNetOpenAuth.OpenId.RelyingParty; + using Org.Mentalis.Security.Cryptography; using Validation; @@ -79,6 +82,15 @@ namespace DotNetOpenAuth.OpenId { return string.Format(CultureInfo.InvariantCulture, "{{{0}}}{{{1}}}", DateTime.UtcNow.Ticks, uniq); } + public static async Task RedirectToProviderAsync(this IAuthenticationRequest authenticationRequest, HttpContextBase context = null, CancellationToken cancellationToken = default(CancellationToken)) { + Requires.NotNull(authenticationRequest, "authenticationRequest"); + Verify.Operation(context != null || HttpContext.Current != null, MessagingStrings.HttpContextRequired); + + context = context ?? new HttpContextWrapper(HttpContext.Current); + var response = await authenticationRequest.GetRedirectingResponseAsync(cancellationToken); + response.Send(context); + } + /// <summary> /// Gets the OpenID protocol instance for the version in a message. /// </summary> |