diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-01 17:34:59 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-01 17:34:59 -0700 |
commit | 6e8a6eb02294c28b13bacaa339e58a67fd766f99 (patch) | |
tree | a1bd58a2a51505ba71b697fb61378e7142df8ef3 /samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs | |
parent | e36299f39476c56977c39700067ed8f6ae0a4e49 (diff) | |
parent | 36b1ba3c75d060fa71f6f15582b90e7f70292ddc (diff) | |
download | DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.zip DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.tar.gz DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.tar.bz2 |
Merge branch 'master' into contracts
Conflicts:
src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs
src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
src/DotNetOpenAuth.vsmdi
src/DotNetOpenAuth/DotNetOpenAuth.csproj
src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs
src/DotNetOpenAuth/OAuth/ChannelElements/OAuthServiceProviderMessageFactory.cs
src/DotNetOpenAuth/OAuth/Protocol.cs
src/DotNetOpenAuth/OAuth/ServiceProvider.cs
src/DotNetOpenAuth/OpenId/Association.cs
src/DotNetOpenAuth/OpenId/Behaviors/PpidGeneration.cs
src/DotNetOpenAuth/OpenId/NoDiscoveryIdentifier.cs
src/DotNetOpenAuth/OpenId/Provider/HostProcessedRequest.cs
src/DotNetOpenAuth/OpenId/Provider/IDirectedIdentityIdentifierProvider.cs
src/DotNetOpenAuth/OpenId/Provider/PrivatePersonalIdentifierProviderBase.cs
src/DotNetOpenAuth/OpenId/Realm.cs
src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs
src/DotNetOpenAuth/OpenId/RelyingParty/PositiveAuthenticationResponseSnapshot.cs
src/DotNetOpenAuth/OpenId/UriIdentifier.cs
src/DotNetOpenAuth/OpenId/XriIdentifier.cs
src/DotNetOpenAuth/Util.cs
Diffstat (limited to 'samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs')
-rw-r--r-- | samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs b/samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs new file mode 100644 index 0000000..b04f736 --- /dev/null +++ b/samples/OpenIdProviderWebForms/Code/InMemoryTokenManager.cs @@ -0,0 +1,117 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace OpenIdProviderWebForms.Code { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Web; + using DotNetOpenAuth.OAuth.ChannelElements; + using DotNetOpenAuth.OAuth.Messages; + using DotNetOpenAuth.OpenId.Extensions.OAuth; + + /// <summary> + /// A simple in-memory token manager. JUST FOR PURPOSES OF KEEPING THE SAMPLE SIMPLE. + /// </summary> + /// <remarks> + /// This is merely a sample app. A real web app SHOULD NEVER store a memory-only + /// token manager in application. It should be an IServiceProviderTokenManager + /// implementation that is bound to a database. + /// </remarks> + public class InMemoryTokenManager : IServiceProviderTokenManager, IOpenIdOAuthTokenManager, ICombinedOpenIdProviderTokenManager { + private Dictionary<string, InMemoryServiceProviderRequestToken> requestTokens = new Dictionary<string, InMemoryServiceProviderRequestToken>(); + private Dictionary<string, InMemoryServiceProviderAccessToken> accessTokens = new Dictionary<string, InMemoryServiceProviderAccessToken>(); + + /// <summary> + /// Initializes a new instance of the <see cref="InMemoryTokenManager"/> class. + /// </summary> + internal InMemoryTokenManager() { + } + + #region IServiceProviderTokenManager Members + + public IConsumerDescription GetConsumer(string consumerKey) { + return new InMemoryConsumerDescription { + Key = consumerKey, + Secret = "some crazy secret", + }; + } + + public IServiceProviderRequestToken GetRequestToken(string token) { + return this.requestTokens[token]; + } + + public IServiceProviderAccessToken GetAccessToken(string token) { + throw new NotImplementedException(); + } + + public void UpdateToken(IServiceProviderRequestToken token) { + // Nothing to do here, since there's not database in this sample. + } + + #endregion + + #region ITokenManager Members + + public string GetTokenSecret(string token) { + if (this.requestTokens.ContainsKey(token)) { + return this.requestTokens[token].Secret; + } else { + return this.accessTokens[token].Secret; + } + } + + public void StoreNewRequestToken(DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest request, DotNetOpenAuth.OAuth.Messages.ITokenSecretContainingMessage response) { + throw new NotImplementedException(); + } + + public bool IsRequestTokenAuthorized(string requestToken) { + // In OpenID+OAuth scenarios, request tokens are always authorized. + return true; + } + + public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) { + this.requestTokens.Remove(requestToken); + this.accessTokens[accessToken] = new InMemoryServiceProviderAccessToken { + Token = accessToken, + Secret = accessTokenSecret, + }; + } + + public TokenType GetTokenType(string token) { + if (this.requestTokens.ContainsKey(token)) { + return TokenType.RequestToken; + } else if (this.accessTokens.ContainsKey(token)) { + return TokenType.AccessToken; + } else { + return TokenType.InvalidToken; + } + } + + #endregion + + #region IOpenIdOAuthTokenManager Members + + public void StoreOpenIdAuthorizedRequestToken(string consumerKey, AuthorizationApprovedResponse authorization) { + this.requestTokens[authorization.RequestToken] = new InMemoryServiceProviderRequestToken { + Token = authorization.RequestToken, + Scope = authorization.Scope, + ConsumerVersion = authorization.Version, + }; + } + + #endregion + + #region ICombinedOpenIdProviderTokenManager Members + + public string GetConsumerKey(DotNetOpenAuth.OpenId.Realm realm) { + // We just use the realm as the consumer key, like Google does. + return realm; + } + + #endregion + } +} |