From 0386773ac51408c71de85012879f341541e5a069 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 6 Apr 2008 19:56:36 -0700 Subject: [PATCH] Unsolicited assertion successfully sent if RP login page is given by user. We still need to add RP discovery to this so that the realm URL can be given by the user rather than the full login page. --- samples/ProviderPortal/Default.aspx | 35 +++++++++++++++++-- samples/RelyingPartyPortal/Default.aspx | 1 + src/DotNetOpenId/Provider/AssertionMessage.cs | 19 ++++++++++ src/DotNetOpenId/Provider/OpenIdProvider.cs | 14 ++++++-- src/DotNetOpenId/Realm.cs | 4 +++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/samples/ProviderPortal/Default.aspx b/samples/ProviderPortal/Default.aspx index 86629e6f5e..17d3f50d4a 100644 --- a/samples/ProviderPortal/Default.aspx +++ b/samples/ProviderPortal/Default.aspx @@ -1,7 +1,19 @@ <%@ Page Language="C#" AutoEventWireup="true" %> -<%@ Register Assembly="DotNetOpenId" Namespace="DotNetOpenId" TagPrefix="openid" %> +<%@ Import Namespace="DotNetOpenId.Provider" %> +<%@ Register Assembly="DotNetOpenId" Namespace="DotNetOpenId" TagPrefix="openid" %> + + + @@ -16,9 +28,26 @@ Provided by DotNetOpenId

- Welcome. This site doesn't do anything more than simple authentication of - users. Start the authentication process on the Relying Party sample site. + Welcome. This site doesn't do anything more than simple authentication of users. + Start the authentication process on the Relying Party sample site, or log in here + and send an unsolicited assertion.

+ + + + Since you're logged in, try sending an unsolicited assertion to an OpenID 2.0 relying + party site. Just type in the URL to the site's home page. This could be the sample + relying party web site. +
+ + + +
+ An unsolicited assertion is a way to log in to a relying party site directly from + your OpenID Provider. +
+
+
diff --git a/samples/RelyingPartyPortal/Default.aspx b/samples/RelyingPartyPortal/Default.aspx index 47f26e963a..b303c120e0 100644 --- a/samples/RelyingPartyPortal/Default.aspx +++ b/samples/RelyingPartyPortal/Default.aspx @@ -20,6 +20,7 @@ area. (This will trigger a login demo).

+ diff --git a/src/DotNetOpenId/Provider/AssertionMessage.cs b/src/DotNetOpenId/Provider/AssertionMessage.cs index 859f3898d9..1957f15a5c 100644 --- a/src/DotNetOpenId/Provider/AssertionMessage.cs +++ b/src/DotNetOpenId/Provider/AssertionMessage.cs @@ -61,5 +61,24 @@ static class AssertionMessage { AssertionMessage.CreateNegativeAssertion(response, request.Immediate, request.SetupUrl); return response; } + + /// + /// Creates a message that can be sent to a user agent to redirect them to a + /// relying party web site complete with authentication information to + /// automatically log them into that web site. + /// + public static IResponse CreateUnsolicitedAssertion(OpenIdProvider provider, + Realm relyingParty, Identifier claimedIdentifier, Identifier localIdentifier) { + if (relyingParty == null) throw new ArgumentNullException("relyingParty"); + if (claimedIdentifier == null) throw new ArgumentNullException("claimedIdentifier"); + if (localIdentifier == null) throw new ArgumentNullException("localIdentifier"); + + Uri relyingPartyLoginUrl = relyingParty.NoWildcardUri; + Protocol protocol = Protocol.Default; + + EncodableResponse message = EncodableResponse.PrepareIndirectMessage(protocol, relyingPartyLoginUrl, null); + CreatePositiveAssertion(message, provider, localIdentifier, claimedIdentifier); + return provider.Encoder.Encode(message); + } } } diff --git a/src/DotNetOpenId/Provider/OpenIdProvider.cs b/src/DotNetOpenId/Provider/OpenIdProvider.cs index 7315aec7da..45525d34c7 100644 --- a/src/DotNetOpenId/Provider/OpenIdProvider.cs +++ b/src/DotNetOpenId/Provider/OpenIdProvider.cs @@ -6,6 +6,7 @@ using ProviderMemoryStore = DotNetOpenId.AssociationMemoryStore; using System.Collections.Generic; using System.Diagnostics; +using System.Net; namespace DotNetOpenId.Provider { /// @@ -41,7 +42,7 @@ public class OpenIdProvider { /// This method requires a current ASP.NET HttpContext. /// public OpenIdProvider() - : this(httpApplicationAssociationStore, + : this(HttpApplicationAssociationStore, getProviderEndpointFromContext(), Util.GetRequestUrlFromContext(), Util.GetQueryFromContext()) { } /// /// Constructs an OpenId server that uses a given query and IAssociationStore. @@ -114,8 +115,17 @@ public OpenIdProvider(IProviderAssociationStore store, Uri providerEndpoint, Uri return req; } + public IResponse PrepareUnsolicitedAssertion(Realm relyingParty, + Identifier claimedIdentifier, Identifier localIdentifier) { + if (relyingParty == null) throw new ArgumentNullException("relyingParty"); + if (claimedIdentifier == null) throw new ArgumentNullException("claimedIdentifier"); + if (localIdentifier == null) throw new ArgumentNullException("localIdentifier"); + return AssertionMessage.CreateUnsolicitedAssertion(this, + relyingParty, claimedIdentifier, localIdentifier); + } + const string associationStoreKey = "DotNetOpenId.Provider.OpenIdProvider.AssociationStore"; - static IProviderAssociationStore httpApplicationAssociationStore { + public static IProviderAssociationStore HttpApplicationAssociationStore { get { HttpContext context = HttpContext.Current; if (context == null) diff --git a/src/DotNetOpenId/Realm.cs b/src/DotNetOpenId/Realm.cs index 2cea647b9e..e757134137 100644 --- a/src/DotNetOpenId/Realm.cs +++ b/src/DotNetOpenId/Realm.cs @@ -72,6 +72,10 @@ public class Realm { /// by a question mark (?). /// public string PathAndQuery { get { return uri.PathAndQuery; } } + /// + /// Gets the realm URL. If the realm includes a wildcard, it is not included here. + /// + internal Uri NoWildcardUri { get { return uri; } } static string[] _top_level_domains = {"com", "edu", "gov", "int", "mil", "net", "org", "biz", "info", "name", "museum", "coop", "aero", "ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj",