summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestWithHasSession.cs39
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj1
-rw-r--r--samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx14
-rw-r--r--samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.cs37
-rw-r--r--samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.designer.cs33
-rw-r--r--samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj8
6 files changed, 132 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestWithHasSession.cs b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestWithHasSession.cs
new file mode 100644
index 0000000..2fa70a3
--- /dev/null
+++ b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/UIRequestWithHasSession.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="UIRequestAtRelyingPartyFactory.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions {
+ using System.Collections.Generic;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.ChannelElements;
+ using DotNetOpenAuth.OpenId.Extensions.UI;
+
+ /// <summary>
+ /// An extension factory that allows the <see cref="UIRequest"/> extension to be received by the relying party.
+ /// </summary>
+ /// <remarks>
+ /// Typically UIRequest is only received by the Provider. But Google mirrors back this data to the relying party
+ /// if our web user is already logged into Google.
+ /// See the OpenIdRelyingPartyWebForms sample's DetectGoogleSession.aspx page for usage of this factory.
+ /// </remarks>
+ public class UIRequestAtRelyingPartyFactory : IOpenIdExtensionFactory {
+ /// <summary>
+ /// The Type URI for the UI extension.
+ /// </summary>
+ private const string UITypeUri = "http://specs.openid.net/extensions/ui/1.0";
+
+ /// <summary>
+ /// Allows UIRequest extensions to be received by the relying party. Useful when Google mirrors back the request
+ /// to indicate that a user is logged in.
+ /// </summary>
+ public DotNetOpenAuth.OpenId.Messages.IOpenIdMessageExtension Create(string typeUri, IDictionary<string, string> data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole) {
+ if (typeUri == UITypeUri && !isProviderRole) {
+ return new UIRequest();
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
index adb1998..64cf154 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
+++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
@@ -87,6 +87,7 @@
<Compile Include="CustomExtensions\Acme.cs" />
<Compile Include="CustomExtensions\AcmeRequest.cs" />
<Compile Include="CustomExtensions\AcmeResponse.cs" />
+ <Compile Include="CustomExtensions\UIRequestWithHasSession.cs" />
<Compile Include="GoogleConsumer.cs" />
<Compile Include="InMemoryTokenManager.cs">
<SubType>Code</SubType>
diff --git a/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx
new file mode 100644
index 0000000..f8b7dfd
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx
@@ -0,0 +1,14 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DetectGoogleSession.aspx.cs"
+ Inherits="OpenIdRelyingPartyWebForms.DetectGoogleSession" ValidateRequest="false"
+ MasterPageFile="~/Site.Master" %>
+
+<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty"
+ TagPrefix="rp" %>
+<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.Extensions.SimpleRegistration"
+ TagPrefix="sreg" %>
+<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Main">
+ <asp:Label Text="We've detected that you're logged into Google!" runat="server" Visible="false"
+ ID="YouAreLoggedInLabel" />
+ <asp:Label Text="We've detected that you're NOT logged into Google!" runat="server" Visible="false"
+ ID="YouAreNotLoggedInLabel" />
+</asp:Content>
diff --git a/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.cs b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.cs
new file mode 100644
index 0000000..bdd6c0d
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.cs
@@ -0,0 +1,37 @@
+namespace OpenIdRelyingPartyWebForms {
+ using System;
+ using DotNetOpenAuth.ApplicationBlock.CustomExtensions;
+ using DotNetOpenAuth.OpenId.Extensions.UI;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+
+ public partial class DetectGoogleSession : System.Web.UI.Page {
+ private const string GoogleOPIdentifier = "https://www.google.com/accounts/o8/id";
+
+ private const string UIModeDetectSession = "x-has-session";
+
+ protected void Page_Load(object sender, EventArgs e) {
+ using (var openid = new OpenIdRelyingParty()) {
+ // In order to receive the UIRequest as a response, we must register a custom extension factory.
+ openid.ExtensionFactories.Add(new UIRequestAtRelyingPartyFactory());
+
+ var response = openid.GetResponse();
+ if (response == null) {
+ // Submit an OpenID request which Google must reply to immediately.
+ // If the user hasn't established a trust relationship with this site yet,
+ // Google will not give us the user identity, but they will tell us whether the user
+ // at least has an active login session with them so we know whether to promote the
+ // "Log in with Google" button.
+ IAuthenticationRequest request = openid.CreateRequest("https://www.google.com/accounts/o8/id");
+ request.AddExtension(new UIRequest { Mode = UIModeDetectSession });
+ request.Mode = AuthenticationRequestMode.Immediate;
+ request.RedirectToProvider();
+ } else {
+ // Now see if the UIRequest was mirrored back to us.
+ var ext = response.GetUntrustedExtension<UIRequest>();
+ this.YouAreLoggedInLabel.Visible = ext != null && ext.Mode == UIModeDetectSession;
+ this.YouAreNotLoggedInLabel.Visible = !this.YouAreLoggedInLabel.Visible;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.designer.cs b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.designer.cs
new file mode 100644
index 0000000..e9f6a46
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/DetectGoogleSession.aspx.designer.cs
@@ -0,0 +1,33 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace OpenIdRelyingPartyWebForms {
+
+
+ public partial class DetectGoogleSession {
+
+ /// <summary>
+ /// YouAreLoggedInLabel control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.WebControls.Label YouAreLoggedInLabel;
+
+ /// <summary>
+ /// YouAreNotLoggedInLabel control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.WebControls.Label YouAreNotLoggedInLabel;
+ }
+}
diff --git a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
index 69c3e91..cbcd758 100644
--- a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
+++ b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
@@ -74,6 +74,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Default.aspx" />
+ <Content Include="DetectGoogleSession.aspx" />
<Content Include="Global.asax" />
<Content Include="images\openid_login.png" />
<Content Include="login.aspx" />
@@ -110,6 +111,13 @@
</Compile>
<Compile Include="Code\State.cs" />
<Compile Include="Code\TracePageAppender.cs" />
+ <Compile Include="DetectGoogleSession.aspx.cs">
+ <DependentUpon>DetectGoogleSession.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="DetectGoogleSession.aspx.designer.cs">
+ <DependentUpon>DetectGoogleSession.aspx</DependentUpon>
+ </Compile>
<Compile Include="loginGoogleApps.aspx.cs">
<DependentUpon>loginGoogleApps.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>