diff options
Diffstat (limited to 'samples/OpenIdRelyingPartyWebForms/Code')
-rw-r--r-- | samples/OpenIdRelyingPartyWebForms/Code/InMemoryTokenManager.cs | 87 | ||||
-rw-r--r-- | samples/OpenIdRelyingPartyWebForms/Code/State.cs | 14 |
2 files changed, 100 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 |