summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdRelyingPartyWebForms
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OpenIdRelyingPartyWebForms')
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Code/InMemoryTokenManager.cs87
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Code/State.cs14
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Global.asax.cs32
-rw-r--r--samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx22
-rw-r--r--samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs41
-rw-r--r--samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.designer.cs70
-rw-r--r--samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj21
-rw-r--r--samples/OpenIdRelyingPartyWebForms/Web.config8
-rw-r--r--samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx30
-rw-r--r--samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs71
-rw-r--r--samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.designer.cs61
11 files changed, 456 insertions, 1 deletions
diff --git a/samples/OpenIdRelyingPartyWebForms/Code/InMemoryTokenManager.cs b/samples/OpenIdRelyingPartyWebForms/Code/InMemoryTokenManager.cs
new file mode 100644
index 0000000..e665cb6
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/Code/InMemoryTokenManager.cs
@@ -0,0 +1,87 @@
+//-----------------------------------------------------------------------
+// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace OpenIdRelyingPartyWebForms.Code {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using DotNetOpenAuth.OAuth.ChannelElements;
+ using DotNetOpenAuth.OAuth.Messages;
+ using DotNetOpenAuth.OpenId.Extensions.OAuth;
+
+ public class InMemoryTokenManager : IConsumerTokenManager, IOpenIdOAuthTokenManager {
+ private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+
+ public InMemoryTokenManager(string consumerKey, string consumerSecret) {
+ if (String.IsNullOrEmpty(consumerKey)) {
+ throw new ArgumentNullException("consumerKey");
+ }
+
+ this.ConsumerKey = consumerKey;
+ this.ConsumerSecret = consumerSecret;
+ }
+
+ public string ConsumerKey { get; private set; }
+
+ public string ConsumerSecret { get; private set; }
+
+ #region ITokenManager Members
+
+ public string GetConsumerSecret(string consumerKey) {
+ if (consumerKey == this.ConsumerKey) {
+ return this.ConsumerSecret;
+ } else {
+ throw new ArgumentException("Unrecognized consumer key.", "consumerKey");
+ }
+ }
+
+ public string GetTokenSecret(string token) {
+ return this.tokensAndSecrets[token];
+ }
+
+ public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response) {
+ this.tokensAndSecrets[response.Token] = response.TokenSecret;
+ }
+
+ /// <summary>
+ /// Checks whether a given request token has already been authorized
+ /// by some user for use by the Consumer that requested it.
+ /// </summary>
+ /// <param name="requestToken">The Consumer's request token.</param>
+ /// <returns>
+ /// True if the request token has already been fully authorized by the user
+ /// who owns the relevant protected resources. False if the token has not yet
+ /// been authorized, has expired or does not exist.
+ /// </returns>
+ public bool IsRequestTokenAuthorized(string requestToken) {
+ throw new NotImplementedException();
+ }
+
+ public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
+ this.tokensAndSecrets.Remove(requestToken);
+ this.tokensAndSecrets[accessToken] = accessTokenSecret;
+ }
+
+ /// <summary>
+ /// Classifies a token as a request token or an access token.
+ /// </summary>
+ /// <param name="token">The token to classify.</param>
+ /// <returns>Request or Access token, or invalid if the token is not recognized.</returns>
+ public TokenType GetTokenType(string token) {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+
+ #region IOpenIdOAuthTokenManager Members
+
+ public void StoreOpenIdAuthorizedRequestToken(string consumerKey, AuthorizationApprovedResponse authorization) {
+ this.tokensAndSecrets[authorization.RequestToken] = string.Empty;
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/samples/OpenIdRelyingPartyWebForms/Code/State.cs b/samples/OpenIdRelyingPartyWebForms/Code/State.cs
index 4861a34..c8147e5 100644
--- a/samples/OpenIdRelyingPartyWebForms/Code/State.cs
+++ b/samples/OpenIdRelyingPartyWebForms/Code/State.cs
@@ -1,6 +1,6 @@
namespace OpenIdRelyingPartyWebForms {
- using System.Collections.Generic;
using System.Web;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
@@ -13,6 +13,11 @@ namespace OpenIdRelyingPartyWebForms {
set { HttpContext.Current.Session["ProfileFields"] = value; }
}
+ public static FetchResponse FetchResponse {
+ get { return HttpContext.Current.Session["FetchResponse"] as FetchResponse; }
+ set { HttpContext.Current.Session["FetchResponse"] = value; }
+ }
+
public static string FriendlyLoginName {
get { return HttpContext.Current.Session["FriendlyUsername"] as string; }
set { HttpContext.Current.Session["FriendlyUsername"] = value; }
@@ -23,10 +28,17 @@ namespace OpenIdRelyingPartyWebForms {
set { HttpContext.Current.Session["PapePolicies"] = value; }
}
+ public static string GoogleAccessToken {
+ get { return HttpContext.Current.Session["GoogleAccessToken"] as string; }
+ set { HttpContext.Current.Session["GoogleAccessToken"] = value; }
+ }
+
public static void Clear() {
ProfileFields = null;
+ FetchResponse = null;
FriendlyLoginName = null;
PapePolicies = null;
+ GoogleAccessToken = null;
}
}
} \ No newline at end of file
diff --git a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
index c7d1e8b..ac74853 100644
--- a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
+++ b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs
@@ -1,15 +1,47 @@
namespace OpenIdRelyingPartyWebForms {
using System;
using System.Collections.Specialized;
+ using System.Configuration;
using System.IO;
using System.Text;
using System.Web;
+ using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.OAuth;
+ using OpenIdRelyingPartyWebForms.Code;
public class Global : HttpApplication {
public static log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(Global));
internal static StringBuilder LogMessages = new StringBuilder();
+ internal static WebConsumer GoogleWebConsumer {
+ get {
+ var googleWebConsumer = (WebConsumer)HttpContext.Current.Application["GoogleWebConsumer"];
+ if (googleWebConsumer == null) {
+ googleWebConsumer = new WebConsumer(GoogleConsumer.ServiceDescription, GoogleTokenManager);
+ HttpContext.Current.Application["GoogleWebConsumer"] = googleWebConsumer;
+ }
+
+ return googleWebConsumer;
+ }
+ }
+
+ internal static InMemoryTokenManager GoogleTokenManager {
+ get {
+ var tokenManager = (InMemoryTokenManager)HttpContext.Current.Application["GoogleTokenManager"];
+ if (tokenManager == null) {
+ string consumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
+ string consumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
+ if (!string.IsNullOrEmpty(consumerKey)) {
+ tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
+ HttpContext.Current.Application["GoogleTokenManager"] = tokenManager;
+ }
+ }
+
+ return tokenManager;
+ }
+ }
+
public static string ToString(NameValueCollection collection) {
using (StringWriter sw = new StringWriter()) {
foreach (string key in collection.Keys) {
diff --git a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx
new file mode 100644
index 0000000..7d5a54f
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx
@@ -0,0 +1,22 @@
+<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="DisplayGoogleContacts.aspx.cs"
+ Inherits="OpenIdRelyingPartyWebForms.MembersOnly.DisplayGoogleContacts" %>
+
+<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Main">
+ <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
+ <asp:View ID="View1" runat="server">
+ <p>Obtain an access token by <asp:HyperLink NavigateUrl="~/loginPlusOAuth.aspx" runat="server"
+ Text="logging in at our OpenID+OAuth hybrid login page" />. </p>
+ <p>If you've already done that, then you might have inadvertently clicked "Allow [this
+ site] to remember me", which causes Google to stop sending the access token that
+ this sample doesn't save. If you did check it, you can restore this sample&#39;s
+ functionality by <a href="https://www.google.com/accounts/IssuedAuthSubTokens">revoking
+ access</a> to this site from your Google Account. </p>
+ </asp:View>
+ <asp:View ID="View2" runat="server">
+ <h2>Address book</h2>
+ <p>These are the contacts for Google Account: <asp:Label ID="emailLabel" runat="server"
+ Font-Bold="True" /> and OpenID <asp:Label ID="claimedIdLabel" runat="server" Font-Bold="True" /></p>
+ <asp:PlaceHolder ID="resultsPlaceholder" runat="server" />
+ </asp:View>
+ </asp:MultiView>
+</asp:Content>
diff --git a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs
new file mode 100644
index 0000000..b14aba1
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs
@@ -0,0 +1,41 @@
+namespace OpenIdRelyingPartyWebForms.MembersOnly {
+ using System;
+ using System.Linq;
+ using System.Text;
+ using System.Web;
+ using System.Web.UI.WebControls;
+ using System.Xml.Linq;
+ using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+
+ public partial class DisplayGoogleContacts : System.Web.UI.Page {
+ protected void Page_Load(object sender, EventArgs e) {
+ if (!string.IsNullOrEmpty(State.GoogleAccessToken)) {
+ this.MultiView1.ActiveViewIndex = 1;
+ if (State.FetchResponse != null && State.FetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email)) {
+ this.emailLabel.Text = State.FetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values[0];
+ } else {
+ this.emailLabel.Text = "unavailable";
+ }
+ this.claimedIdLabel.Text = this.User.Identity.Name;
+ var contactsDocument = GoogleConsumer.GetContacts(Global.GoogleWebConsumer, State.GoogleAccessToken);
+ this.RenderContacts(contactsDocument);
+ }
+ }
+
+ private void RenderContacts(XDocument contactsDocument) {
+ var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
+ select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value };
+ StringBuilder tableBuilder = new StringBuilder();
+ tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>");
+ foreach (var contact in contacts) {
+ tableBuilder.AppendFormat(
+ "<tr><td>{0}</td><td>{1}</td></tr>",
+ HttpUtility.HtmlEncode(contact.Name),
+ HttpUtility.HtmlEncode(contact.Email));
+ }
+ tableBuilder.Append("</table>");
+ this.resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() });
+ }
+ }
+}
diff --git a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.designer.cs b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.designer.cs
new file mode 100644
index 0000000..5cc5894
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.designer.cs
@@ -0,0 +1,70 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace OpenIdRelyingPartyWebForms.MembersOnly {
+
+
+ public partial class DisplayGoogleContacts {
+
+ /// <summary>
+ /// MultiView1 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.MultiView MultiView1;
+
+ /// <summary>
+ /// View1 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.View View1;
+
+ /// <summary>
+ /// View2 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.View View2;
+
+ /// <summary>
+ /// emailLabel 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 emailLabel;
+
+ /// <summary>
+ /// claimedIdLabel 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 claimedIdLabel;
+
+ /// <summary>
+ /// resultsPlaceholder 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.PlaceHolder resultsPlaceholder;
+ }
+}
diff --git a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
index cf40440..c45f007 100644
--- a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
+++ b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj
@@ -98,6 +98,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>CustomStoreDataSet.xsd</DependentUpon>
</Compile>
+ <Compile Include="Code\InMemoryTokenManager.cs" />
<Compile Include="Code\State.cs" />
<Compile Include="Code\TracePageAppender.cs" />
<Compile Include="Global.asax.cs">
@@ -110,6 +111,13 @@
<Compile Include="login.aspx.designer.cs">
<DependentUpon>login.aspx</DependentUpon>
</Compile>
+ <Compile Include="loginPlusOAuth.aspx.cs">
+ <DependentUpon>loginPlusOAuth.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="loginPlusOAuth.aspx.designer.cs">
+ <DependentUpon>loginPlusOAuth.aspx</DependentUpon>
+ </Compile>
<Compile Include="loginProgrammatic.aspx.cs">
<DependentUpon>loginProgrammatic.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -117,6 +125,13 @@
<Compile Include="loginProgrammatic.aspx.designer.cs">
<DependentUpon>loginProgrammatic.aspx</DependentUpon>
</Compile>
+ <Compile Include="MembersOnly\DisplayGoogleContacts.aspx.cs">
+ <DependentUpon>DisplayGoogleContacts.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="MembersOnly\DisplayGoogleContacts.aspx.designer.cs">
+ <DependentUpon>DisplayGoogleContacts.aspx</DependentUpon>
+ </Compile>
<Compile Include="m\Login.aspx.cs">
<DependentUpon>Login.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -144,6 +159,8 @@
<Content Include="images\dotnetopenid_tiny.gif" />
<Content Include="images\openid_login.gif" />
<Content Include="images\yahoo.png" />
+ <Content Include="loginPlusOAuth.aspx" />
+ <Content Include="MembersOnly\DisplayGoogleContacts.aspx" />
<Content Include="MembersOnly\Web.config" />
<Content Include="m\Login.aspx" />
</ItemGroup>
@@ -165,6 +182,10 @@
<Project>{3191B653-F76D-4C1A-9A5A-347BC3AAAAB7}</Project>
<Name>DotNetOpenAuth</Name>
</ProjectReference>
+ <ProjectReference Include="..\DotNetOpenAuth.ApplicationBlock\DotNetOpenAuth.ApplicationBlock.csproj">
+ <Project>{AA78D112-D889-414B-A7D4-467B34C7B663}</Project>
+ <Name>DotNetOpenAuth.ApplicationBlock</Name>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
diff --git a/samples/OpenIdRelyingPartyWebForms/Web.config b/samples/OpenIdRelyingPartyWebForms/Web.config
index d79b1ed..b3536b9 100644
--- a/samples/OpenIdRelyingPartyWebForms/Web.config
+++ b/samples/OpenIdRelyingPartyWebForms/Web.config
@@ -43,6 +43,14 @@
</messaging>
</dotNetOpenAuth>
+ <appSettings>
+ <!-- Fill in your various consumer keys and secrets here to make the sample work. -->
+ <!-- You must get these values by signing up with each individual service provider. -->
+ <!-- Google sign-up: https://www.google.com/accounts/ManageDomains -->
+ <add key="googleConsumerKey" value="demo.dotnetopenauth.net"/>
+ <add key="googleConsumerSecret" value="5Yv1TfKm1551QrXZ9GpqepeD"/>
+ </appSettings>
+
<system.web>
<!--<sessionState cookieless="true" />-->
<compilation debug="true"/>
diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx
new file mode 100644
index 0000000..57bca52
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx
@@ -0,0 +1,30 @@
+<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="loginPlusOAuth.aspx.cs"
+ Inherits="OpenIdRelyingPartyWebForms.loginPlusOAuth" ValidateRequest="false"
+ MasterPageFile="~/Site.Master" %>
+
+<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty"
+ TagPrefix="rp" %>
+<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="Main">
+ <h2>Login Page </h2>
+ <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex='0'>
+ <asp:View ID="View1" runat="server">
+ <p><b>Important note:</b> Do <b>not</b> check the &quot;Allow [this site] to remember me&quot;
+ check box while Google is asking for verification. Doing so will make this
+ sample only work once for your account. If you do check it, you can restore this
+ sample&#39;s functionality by <a href="https://www.google.com/accounts/IssuedAuthSubTokens">
+ revoking access</a> to this site from your Google Account. </p>
+ <asp:Button ID="beginButton" runat="server" Text="Login and get Gmail Contacts" OnClick="beginButton_Click" />
+ <p>Due to the way Google matches realms and consumer keys, this demo will only work
+ when it is run under http://demo.dotnetopenauth.net/. By registering your own consumer
+ key with Google and changing the configuration of this sample, you can run it on
+ your own public web site, but it can never work from a private (localhost or firewall-protected)
+ address. </p>
+ </asp:View>
+ <asp:View ID="AuthorizationDenied" runat="server">
+ Authentication succeeded, but Gmail Contacts access was denied.
+ </asp:View>
+ <asp:View ID="AuthenticationFailed" runat="server">
+ Authentication failed or was canceled.
+ </asp:View>
+ </asp:MultiView>
+</asp:Content>
diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs
new file mode 100644
index 0000000..d4e9885
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs
@@ -0,0 +1,71 @@
+namespace OpenIdRelyingPartyWebForms {
+ using System;
+ using System.Web.Security;
+ using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.OAuth.Messages;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+
+ public partial class loginPlusOAuth : System.Web.UI.Page {
+ private const string GoogleOPIdentifier = "https://www.google.com/accounts/o8/id";
+ private static readonly OpenIdRelyingParty relyingParty = new OpenIdRelyingParty();
+
+ protected void Page_Load(object sender, EventArgs e) {
+ if (!IsPostBack && string.Equals(Request.Url.Host, "localhost", StringComparison.OrdinalIgnoreCase)) {
+ // Disable the button since the scenario won't work under localhost,
+ // and this will help encourage the user to read the the text above the button.
+ this.beginButton.Enabled = false;
+ }
+
+ IAuthenticationResponse authResponse = relyingParty.GetResponse();
+ if (authResponse != null) {
+ switch (authResponse.Status) {
+ case AuthenticationStatus.Authenticated:
+ State.FetchResponse = authResponse.GetExtension<FetchResponse>();
+ AuthorizedTokenResponse accessToken = Global.GoogleWebConsumer.ProcessUserAuthorization(authResponse);
+ if (accessToken != null) {
+ State.GoogleAccessToken = accessToken.AccessToken;
+ FormsAuthentication.SetAuthCookie(authResponse.ClaimedIdentifier, false);
+ Response.Redirect("~/MembersOnly/DisplayGoogleContacts.aspx");
+ } else {
+ MultiView1.SetActiveView(AuthorizationDenied);
+ }
+ break;
+ case AuthenticationStatus.Canceled:
+ case AuthenticationStatus.Failed:
+ default:
+ this.MultiView1.SetActiveView(this.AuthenticationFailed);
+ break;
+ }
+ }
+ }
+
+ protected void beginButton_Click(object sender, EventArgs e) {
+ this.GetGoogleRequest().RedirectToProvider();
+ }
+
+ private IAuthenticationRequest GetGoogleRequest() {
+ // Google requires that the realm and consumer key be equal,
+ // so we constrain the realm to match the realm in the web.config file.
+ // This does mean that the return_to URL must also fall under the key,
+ // which means this sample will only work on a public web site
+ // that is properly registered with Google.
+ // We will customize the realm to use http or https based on what the
+ // return_to URL will be (which will be this page).
+ Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/";
+ IAuthenticationRequest authReq = relyingParty.CreateRequest(GoogleOPIdentifier, realm);
+
+ // Prepare the OAuth extension
+ string scope = GoogleConsumer.GetScopeUri(GoogleConsumer.Applications.Contacts);
+ Global.GoogleWebConsumer.AttachAuthorizationRequest(authReq, scope);
+
+ // We also want the user's email address
+ var fetch = new FetchRequest();
+ fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
+ authReq.AddExtension(fetch);
+
+ return authReq;
+ }
+ }
+}
diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.designer.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.designer.cs
new file mode 100644
index 0000000..b9c836d
--- /dev/null
+++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.designer.cs
@@ -0,0 +1,61 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace OpenIdRelyingPartyWebForms {
+
+
+ public partial class loginPlusOAuth {
+
+ /// <summary>
+ /// MultiView1 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.MultiView MultiView1;
+
+ /// <summary>
+ /// View1 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.View View1;
+
+ /// <summary>
+ /// beginButton 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.Button beginButton;
+
+ /// <summary>
+ /// AuthorizationDenied 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.View AuthorizationDenied;
+
+ /// <summary>
+ /// AuthenticationFailed 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.View AuthenticationFailed;
+ }
+}