summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-05-21 17:55:16 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-05-21 17:55:16 -0700
commita05c016a9c73ba3c1d880e2f60be504bcbc36104 (patch)
treed022eeb4fa8c0b618db3fd777ba483647c9f2233 /samples/DotNetOpenAuth.ApplicationBlock
parentbaa8dcc4fb574fe81ae701eb9020d10684158781 (diff)
parent683b55a61af3c7bfa11b74a5cc4efd3556e59613 (diff)
downloadDotNetOpenAuth-a05c016a9c73ba3c1d880e2f60be504bcbc36104.zip
DotNetOpenAuth-a05c016a9c73ba3c1d880e2f60be504bcbc36104.tar.gz
DotNetOpenAuth-a05c016a9c73ba3c1d880e2f60be504bcbc36104.tar.bz2
Merge branch 'v3.1'
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeRequest.cs5
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeResponse.cs5
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj2
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs76
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs63
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs67
6 files changed, 214 insertions, 4 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeRequest.cs b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeRequest.cs
index e3effdf..8859c10 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeRequest.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeRequest.cs
@@ -8,12 +8,15 @@ namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions {
using System;
using System.Collections.Generic;
using System.Linq;
- using System.Text;
+ using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.Messages;
public class AcmeRequest : IOpenIdMessageExtension {
private IDictionary<string, string> extraData = new Dictionary<string, string>();
+ [MessagePart]
+ public string FavoriteFlavor { get; set; }
+
#region IOpenIdMessageExtension Members
public string TypeUri {
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeResponse.cs b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeResponse.cs
index 62551e6..1e6748c 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeResponse.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/CustomExtensions/AcmeResponse.cs
@@ -8,13 +8,16 @@ namespace DotNetOpenAuth.ApplicationBlock.CustomExtensions {
using System;
using System.Collections.Generic;
using System.Linq;
- using System.Text;
+ using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.Messages;
[Serializable]
public class AcmeResponse : IOpenIdMessageExtension {
private IDictionary<string, string> extraData = new Dictionary<string, string>();
+ [MessagePart]
+ public string FavoriteIceCream { get; set; }
+
#region IOpenIdMessageExtension Members
/// <summary>
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
index 83d3527..570d91f 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
+++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
@@ -59,6 +59,8 @@
<Compile Include="CustomExtensions\AcmeRequest.cs" />
<Compile Include="CustomExtensions\AcmeResponse.cs" />
<Compile Include="GoogleConsumer.cs" />
+ <Compile Include="OAuthIdentity.cs" />
+ <Compile Include="OAuthPrincipal.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Provider\AnonymousIdentifierProviderBase.cs" />
<Compile Include="Provider\AuthenticationRequestExtensions.cs" />
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
index 4bcca86..e8511ae 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
@@ -38,9 +38,21 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// A mapping between Google's applications and their URI scope values.
/// </summary>
private static readonly Dictionary<Applications, string> DataScopeUris = new Dictionary<Applications, string> {
- { Applications.Contacts, "http://www.google.com/m8/feeds/" },
- { Applications.Calendar, "http://www.google.com/calendar/feeds/" },
+ { Applications.Analytics, "https://www.google.com/analytics/feeds/" },
+ { Applications.GoogleBase, "http://www.google.com/base/feeds/" },
{ Applications.Blogger, "http://www.blogger.com/feeds" },
+ { Applications.BookSearch, "http://www.google.com/books/feeds/" },
+ { Applications.Calendar, "http://www.google.com/calendar/feeds/" },
+ { Applications.Contacts, "http://www.google.com/m8/feeds/" },
+ { Applications.DocumentsList, "http://docs.google.com/feeds/" },
+ { Applications.Finance, "http://finance.google.com/finance/feeds/" },
+ { Applications.Gmail, "https://mail.google.com/mail/feed/atom" },
+ { Applications.Health, "https://www.google.com/h9/feeds/" },
+ { Applications.OpenSocial, "http://sandbox.gmodules.com/api/" },
+ { Applications.PicasaWeb, "http://picasaweb.google.com/data/" },
+ { Applications.Spreadsheets, "http://spreadsheets.google.com/feeds/" },
+ { Applications.WebmasterTools, "http://www.google.com/webmasters/tools/feeds/" },
+ { Applications.YouTube, "http://gdata.youtube.com" },
};
/// <summary>
@@ -67,6 +79,66 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// Blog post authoring.
/// </summary>
Blogger = 0x4,
+
+ /// <summary>
+ /// Google Finance
+ /// </summary>
+ Finance = 0x8,
+
+ /// <summary>
+ /// Google Gmail
+ /// </summary>
+ Gmail = 0x10,
+
+ /// <summary>
+ /// Google Health
+ /// </summary>
+ Health = 0x20,
+
+ /// <summary>
+ /// Google OpenSocial
+ /// </summary>
+ OpenSocial = 0x40,
+
+ /// <summary>
+ /// Picasa Web
+ /// </summary>
+ PicasaWeb = 0x80,
+
+ /// <summary>
+ /// Google Spreadsheets
+ /// </summary>
+ Spreadsheets = 0x100,
+
+ /// <summary>
+ /// Webmaster Tools
+ /// </summary>
+ WebmasterTools = 0x200,
+
+ /// <summary>
+ /// YouTube service
+ /// </summary>
+ YouTube = 0x400,
+
+ /// <summary>
+ /// Google Docs
+ /// </summary>
+ DocumentsList = 0x800,
+
+ /// <summary>
+ /// Google Book Search
+ /// </summary>
+ BookSearch = 0x1000,
+
+ /// <summary>
+ /// Google Base
+ /// </summary>
+ GoogleBase = 0x2000,
+
+ /// <summary>
+ /// Google Analytics
+ /// </summary>
+ Analytics = 0x4000,
}
/// <summary>
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs b/samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs
new file mode 100644
index 0000000..ea9ec0b
--- /dev/null
+++ b/samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthIdentity.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.ApplicationBlock {
+ using System;
+ using System.Runtime.InteropServices;
+ using System.Security.Principal;
+
+ /// <summary>
+ /// Represents an OAuth consumer that is impersonating a known user on the system.
+ /// </summary>
+ [Serializable]
+ [ComVisible(true)]
+ internal class OAuthIdentity : IIdentity {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthIdentity"/> class.
+ /// </summary>
+ /// <param name="username">The username.</param>
+ internal OAuthIdentity(string username) {
+ if (String.IsNullOrEmpty(username)) {
+ throw new ArgumentNullException("username");
+ }
+
+ this.Name = username;
+ }
+
+ #region IIdentity Members
+
+ /// <summary>
+ /// Gets the type of authentication used.
+ /// </summary>
+ /// <value>The constant "OAuth"</value>
+ /// <returns>
+ /// The type of authentication used to identify the user.
+ /// </returns>
+ public string AuthenticationType {
+ get { return "OAuth"; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether the user has been authenticated.
+ /// </summary>
+ /// <value>The value <c>true</c></value>
+ /// <returns>true if the user was authenticated; otherwise, false.
+ /// </returns>
+ public bool IsAuthenticated {
+ get { return true; }
+ }
+
+ /// <summary>
+ /// Gets the name of the user who authorized the OAuth token the consumer is using for authorization.
+ /// </summary>
+ /// <returns>
+ /// The name of the user on whose behalf the code is running.
+ /// </returns>
+ public string Name { get; private set; }
+
+ #endregion
+ }
+}
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs b/samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs
new file mode 100644
index 0000000..88f3b83
--- /dev/null
+++ b/samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs
@@ -0,0 +1,67 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthPrincipal.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.ApplicationBlock {
+ using System;
+ using System.Linq;
+ using System.Runtime.InteropServices;
+ using System.Security.Principal;
+
+ /// <summary>
+ /// Represents an OAuth consumer that is impersonating a known user on the system.
+ /// </summary>
+ [Serializable]
+ [ComVisible(true)]
+ internal class OAuthPrincipal : IPrincipal {
+ /// <summary>
+ /// The roles this user belongs to.
+ /// </summary>
+ private string[] roles;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
+ /// </summary>
+ /// <param name="identity">The identity.</param>
+ /// <param name="roles">The roles this user belongs to.</param>
+ internal OAuthPrincipal(OAuthIdentity identity, string[] roles) {
+ this.Identity = identity;
+ this.roles = roles;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
+ /// </summary>
+ /// <param name="username">The username.</param>
+ /// <param name="roles">The roles this user belongs to.</param>
+ internal OAuthPrincipal(string username, string[] roles)
+ : this(new OAuthIdentity(username), roles) {
+ }
+
+ #region IPrincipal Members
+
+ /// <summary>
+ /// Gets the identity of the current principal.
+ /// </summary>
+ /// <value></value>
+ /// <returns>
+ /// The <see cref="T:System.Security.Principal.IIdentity"/> object associated with the current principal.
+ /// </returns>
+ public IIdentity Identity { get; private set; }
+
+ /// <summary>
+ /// Determines whether the current principal belongs to the specified role.
+ /// </summary>
+ /// <param name="role">The name of the role for which to check membership.</param>
+ /// <returns>
+ /// true if the current principal is a member of the specified role; otherwise, false.
+ /// </returns>
+ public bool IsInRole(string role) {
+ return this.roles.Contains(role);
+ }
+
+ #endregion
+ }
+}