diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-29 14:32:45 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-29 14:32:45 -0800 |
commit | 5fec515095ee10b522f414a03e78f282aaf520dc (patch) | |
tree | 204c75486639c23cdda2ef38b34d7e5050a1a2e3 /src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs | |
parent | f1a4155398635a4fd9f485eec817152627682704 (diff) | |
parent | 8f4165ee515728aca3faaa26e8354a40612e85e4 (diff) | |
download | DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.zip DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.gz DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.bz2 |
Merge branch 'splitDlls'.
DNOA now builds and (in some cases) ships as many distinct assemblies.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs')
-rw-r--r-- | src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs new file mode 100644 index 0000000..d18f5fe --- /dev/null +++ b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/StandardTokenGenerator.cs @@ -0,0 +1,64 @@ +//----------------------------------------------------------------------- +// <copyright file="StandardTokenGenerator.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuth.ChannelElements { + using System; + using System.Security.Cryptography; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A cryptographically strong random string generator for tokens and secrets. + /// </summary> + internal class StandardTokenGenerator : ITokenGenerator { + #region ITokenGenerator Members + + /// <summary> + /// Generates a new token to represent a not-yet-authorized request to access protected resources. + /// </summary> + /// <param name="consumerKey">The consumer that requested this token.</param> + /// <returns>The newly generated token.</returns> + /// <remarks> + /// This method should not store the newly generated token in any persistent store. + /// This will be done in <see cref="ITokenManager.StoreNewRequestToken"/>. + /// </remarks> + public string GenerateRequestToken(string consumerKey) { + return GenerateCryptographicallyStrongString(); + } + + /// <summary> + /// Generates a new token to represent an authorized request to access protected resources. + /// </summary> + /// <param name="consumerKey">The consumer that requested this token.</param> + /// <returns>The newly generated token.</returns> + /// <remarks> + /// This method should not store the newly generated token in any persistent store. + /// This will be done in <see cref="ITokenManager.ExpireRequestTokenAndStoreNewAccessToken"/>. + /// </remarks> + public string GenerateAccessToken(string consumerKey) { + return GenerateCryptographicallyStrongString(); + } + + /// <summary> + /// Returns a cryptographically strong random string for use as a token secret. + /// </summary> + /// <returns>The generated string.</returns> + public string GenerateSecret() { + return GenerateCryptographicallyStrongString(); + } + + #endregion + + /// <summary> + /// Returns a new random string. + /// </summary> + /// <returns>The new random string.</returns> + private static string GenerateCryptographicallyStrongString() { + byte[] buffer = new byte[20]; + MessagingUtilities.CryptoRandomDataGenerator.GetBytes(buffer); + return Convert.ToBase64String(buffer); + } + } +} |