Permalink
Browse files

removing dependancy on devdefined libraries

  • Loading branch information...
1 parent a06cb05 commit 53b93d8eccfc9fdbe5c05144ea7bcf2ee95aa097 @buildmaster committed Sep 1, 2009
Showing with 13,472 additions and 199 deletions.
  1. +25 −0 Core/OAuth.Core/AccessDeniedException.cs
  2. +11 −0 Core/OAuth.Core/AccessOutcome.cs
  3. +30 −0 Core/OAuth.Core/CertificateUtility.cs
  4. +19 −0 Core/OAuth.Core/DateTimeUtility.cs
  5. +148 −0 Core/OAuth.Core/Error.cs
  6. +32 −0 Core/OAuth.Core/Interfaces/IOAuthContext.cs
  7. +9 −0 Core/OAuth.Core/Interfaces/IOAuthContextBuilder.cs
  8. +9 −0 Core/OAuth.Core/Interfaces/IOAuthProvider.cs
  9. +14 −0 Core/OAuth.Core/Interfaces/IToken.cs
  10. +824 −0 Core/OAuth.Core/KeyInterop/AsnKeyParser.cs
  11. +70 −0 Core/OAuth.Core/KeyInterop/BerDecodeException.cs
  12. +3,292 −0 Core/OAuth.Core/KeyInterop/BigInteger.cs
  13. +102 −0 Core/OAuth.Core/OAuth.Core.csproj
  14. +340 −0 Core/OAuth.Core/OAuthContext.cs
  15. +124 −0 Core/OAuth.Core/OAuthContextBuilder.cs
  16. +35 −0 Core/OAuth.Core/OAuthException.cs
  17. +77 −0 Core/OAuth.Core/OAuthProblemReport.cs
  18. +24 −0 Core/OAuth.Core/OAuthProblems.cs
  19. +36 −0 Core/OAuth.Core/Properties/AssemblyInfo.cs
  20. +29 −0 Core/OAuth.Core/Protocol.cs
  21. +29 −0 Core/OAuth.Core/Provider/Inspectors/ConsumerValidationInspector.cs
  22. +9 −0 Core/OAuth.Core/Provider/Inspectors/IContextInspector.cs
  23. +29 −0 Core/OAuth.Core/Provider/Inspectors/NonceStoreInspector.cs
  24. +56 −0 Core/OAuth.Core/Provider/Inspectors/SignatureValidationInspector.cs
  25. +55 −0 Core/OAuth.Core/Provider/Inspectors/TimestampRangeInspector.cs
  26. +79 −0 Core/OAuth.Core/Provider/OAuthProvider.cs
  27. +9 −0 Core/OAuth.Core/SignatureMethod.cs
  28. +37 −0 Core/OAuth.Core/Signing/HmacSha1SignatureGenerator.cs
  29. +62 −0 Core/OAuth.Core/Signing/HmacSha1SignatureImplementation.cs
  30. +11 −0 Core/OAuth.Core/Signing/IContextSignatureImplementation.cs
  31. +11 −0 Core/OAuth.Core/Signing/IOAuthContextSigner.cs
  32. +8 −0 Core/OAuth.Core/Signing/ISignatureGenerator.cs
  33. +50 −0 Core/OAuth.Core/Signing/OAuthContextSigner.cs
  34. +31 −0 Core/OAuth.Core/Signing/PlainTextSignatureImplementation.cs
  35. +65 −0 Core/OAuth.Core/Signing/RsaSha1SignatureImplementation.cs
  36. +11 −0 Core/OAuth.Core/SigningContext.cs
  37. +14 −0 Core/OAuth.Core/Storage/Interfaces/IConsumerStore.cs
  38. +18 −0 Core/OAuth.Core/Storage/Interfaces/INonceStore.cs
  39. +42 −0 Core/OAuth.Core/Storage/Interfaces/ITokenStore.cs
  40. +9 −0 Core/OAuth.Core/Storage/RequestForAccessStatus.cs
  41. +24 −0 Core/OAuth.Core/TokenBase.cs
  42. +232 −0 Core/OAuth.Core/UriUtility.cs
  43. +3 −2 Core/OAuth.MVC.Library/Binders/OAuthBinder.cs
  44. +10 −11 Core/OAuth.MVC.Library/Controllers/OAuthController.cs
  45. +3 −4 Core/OAuth.MVC.Library/Filters/OAuthSecuredAttribute.cs
  46. +15 −6 Core/OAuth.MVC.Library/OAuth.MVC.Library.csproj
  47. +6 −6 Core/OAuth.MVC.Library/Results/OAuthExceptionResult.cs
  48. +4 −4 Core/OAuth.MVC.Library/Results/OAuthTokenResult.cs
  49. +5 −5 Core/OAuth.Web/IOAuthToken.cs
  50. +6 −5 Core/OAuth.Web/OAuth.Web.csproj
  51. +2 −0 Core/OAuth.Web/OAuthHttpWebRequest.cs
  52. +2 −1 Core/OAuth.Web/OAuthWebRequestSigner.cs
  53. BIN Lib/Ninject/Ninject.Extensions.Wcf.dll
  54. BIN Lib/Ninject/Ninject.Extensions.Wcf.pdb
  55. +225 −0 Lib/Ninject/Ninject.Extensions.Wcf.xml
  56. BIN Lib/Ninject/Ninject.Web.Mvc.dll
  57. BIN Lib/Ninject/Ninject.Web.Mvc.pdb
  58. +140 −0 Lib/Ninject/Ninject.Web.Mvc.xml
  59. BIN Lib/Ninject/Ninject.dll
  60. BIN Lib/Ninject/Ninject.pdb
  61. +3,801 −0 Lib/Ninject/Ninject.xml
  62. BIN Lib/xunit/xunit.dll
  63. BIN Lib/xunit/xunit.extensions.dll
  64. +705 −0 Lib/xunit/xunit.extensions.xml
  65. +2,132 −0 Lib/xunit/xunit.xml
  66. +6 −0 OAuth MVC.sln
  67. +8 −7 Sample/OAuth.MVC.Sample/Controllers/AccountController.cs
  68. +4 −4 Sample/OAuth.MVC.Sample/Controllers/HomeController.cs
  69. +137 −43 Sample/OAuth.MVC.Sample/Global.asax.cs
  70. +12 −17 Sample/OAuth.MVC.Sample/OAuth.MVC.Sample.csproj
  71. +14 −12 Tests/OAuth.MVC.Tests/Binders/OAuthBinderSpecifications.cs
  72. +21 −19 Tests/OAuth.MVC.Tests/Controllers/OAuthControllerSpecifications.cs
  73. +18 −16 Tests/OAuth.MVC.Tests/Filters/OAuthSecuredAttributeSpecifications.cs
  74. +7 −7 Tests/OAuth.MVC.Tests/OAuth.MVC.Tests.csproj
  75. +28 −23 Tests/OAuth.MVC.Tests/Results/OAuthExceptionResultSpecifications.cs
  76. +2 −1 Tests/OAuth.MVC.Tests/TestClasses.cs
  77. +5 −1 Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs
  78. +7 −4 Tests/OAuth.Web.Tests/OAuth.Web.Tests.csproj
  79. +3 −1 Tests/OAuth.Web.Tests/OAuthWebRequestSignerSpecifications.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace OAuth.Core
+{
+ public class AccessDeniedException : Exception
+ {
+ readonly AccessOutcome _outcome;
+
+ public AccessDeniedException(AccessOutcome outcome)
+ : this(outcome, null)
+ {
+ }
+
+ public AccessDeniedException(AccessOutcome outcome, string message)
+ : base(message)
+ {
+ _outcome = outcome;
+ }
+
+ public AccessOutcome Outcome
+ {
+ get { return _outcome; }
+ }
+ }
+}
@@ -0,0 +1,11 @@
+using OAuth.Core.Interfaces;
+
+namespace OAuth.Core
+{
+ public class AccessOutcome
+ {
+ public bool Granted { get; set; }
+ public string AdditionalInfo { get; set; }
+ public IOAuthContext Context { get; set; }
+ }
+}
@@ -0,0 +1,30 @@
+using System;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using OAuth.Core.KeyInterop;
+
+namespace OAuth.Core
+{
+ public static class CertificateUtility
+ {
+ /// <summary>
+ /// Loads a certificate given both it's private and public keys - generally used to
+ /// load keys provided on the OAuth wiki's for verification of implementation correctness.
+ /// </summary>
+ /// <param name="privateKey"></param>
+ /// <param name="certificate"></param>
+ /// <returns></returns>
+ public static X509Certificate2 LoadCertificateFromStrings(string privateKey, string certificate)
+ {
+ var parser = new AsnKeyParser(Convert.FromBase64String(privateKey));
+ RSAParameters parameters = parser.ParseRSAPrivateKey();
+ var x509 = new X509Certificate2(Encoding.ASCII.GetBytes(certificate));
+ var provider = new RSACryptoServiceProvider();
+ provider.ImportParameters(parameters);
+ x509.PrivateKey = provider;
+
+ return x509;
+ }
+ }
+}
@@ -0,0 +1,19 @@
+using System;
+
+namespace OAuth.Core
+{
+ public static class DateTimeUtility
+ {
+ public static long Epoch(this DateTime d)
+ {
+ return (long)(d.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds;
+ }
+
+ public static DateTime FromEpoch(long epoch)
+ {
+ var d = new DateTime(1970, 1, 1);
+ d = d.AddSeconds(epoch);
+ return d.ToLocalTime();
+ }
+ }
+}
View
@@ -0,0 +1,148 @@
+using System;
+using System.IO;
+using System.Net;
+using OAuth.Core.Interfaces;
+
+namespace OAuth.Core
+{
+ public static class Error
+ {
+ public static Exception MissingRequiredOAuthParameter(IOAuthContext context, string parameterName)
+ {
+ var exception = new OAuthException(context, OAuthProblems.ParameterAbset,
+ string.Format("Missing required parameter : {0}", parameterName));
+
+ exception.Report.ParametersAbsent.Add(parameterName);
+
+ return exception;
+ }
+
+ public static Exception OAuthAuthenticationFailure(string errorMessage)
+ {
+ return new Exception(string.Format("OAuth authentication failed, message was: {0}", errorMessage));
+ }
+
+ public static Exception TokenCanNoLongerBeUsed(string token)
+ {
+ return new Exception(string.Format("Token \"{0}\" is no longer valid", token));
+ }
+
+ public static Exception FailedToParseResponse(string parameters)
+ {
+ return new Exception(string.Format("Failed to parse response string \"{0}\"", parameters));
+ }
+
+ public static Exception UnknownSignatureMethod(string signatureMethod)
+ {
+ return new Exception(string.Format("Unknown signature method \"{0}\"", signatureMethod));
+ }
+
+ public static Exception ForRsaSha1SignatureMethodYouMustSupplyAssymetricKeyParameter()
+ {
+ return
+ new Exception(
+ "For the RSASSA-PKCS1-v1_5 signature method you must use the constructor which takes an additional AssymetricAlgorithm \"key\" parameter");
+ }
+
+ public static Exception RequestFailed(WebException innerException)
+ {
+ var response = innerException.Response as HttpWebResponse;
+
+ if (response != null)
+ {
+ using (var reader = new StreamReader(innerException.Response.GetResponseStream()))
+ {
+ string body = reader.ReadToEnd();
+
+ return
+ new Exception(
+ string.Format(
+ "Request for uri: {0} failed.\r\nstatus code: {1}\r\nheaders: {2}\r\nbody:\r\n{3}",
+ response.ResponseUri, response.StatusCode, response.Headers, body));
+ }
+ }
+
+ return innerException;
+ }
+
+ public static Exception EmptyConsumerKey()
+ {
+ throw new Exception("Consumer key is null or empty");
+ }
+
+ public static Exception RequestMethodHasNotBeenAssigned(string parameter)
+ {
+ return new Exception(string.Format("The RequestMethod parameter \"{0}\" is null or empty.", parameter));
+ }
+
+ public static Exception FailedToValidateSignature(IOAuthContext context)
+ {
+ return new OAuthException(context, OAuthProblems.SignatureInvalid, "Failed to validate signature");
+ }
+
+ public static Exception UnknownConsumerKey(IOAuthContext context)
+ {
+ return new OAuthException(context, OAuthProblems.ConsumerKeyUnknown,
+ string.Format("Unknown Consumer (Realm: {0}, Key: {1})", context.Realm,
+ context.ConsumerKey));
+ }
+
+ public static Exception AlgorithmPropertyNotSetOnSigningContext()
+ {
+ return
+ new Exception(
+ "Algorithm Property must be set on SingingContext when using an Assymetric encryption method such as RSA-SHA1");
+ }
+
+ public static Exception SuppliedTokenWasNotIssuedToThisConsumer(string expectedConsumerKey,
+ string actualConsumerKey)
+ {
+ return
+ new Exception(
+ string.Format("Supplied token was not issued to this consumer, expected key: {0}, actual key: {1}",
+ expectedConsumerKey, actualConsumerKey));
+ }
+
+ public static Exception AccessDeniedToProtectedResource(AccessOutcome outcome)
+ {
+ Uri uri = outcome.Context.GenerateUri();
+
+ if (string.IsNullOrEmpty(outcome.AdditionalInfo))
+ {
+ return new AccessDeniedException(outcome, string.Format("Access to resource \"{0}\" was denied", uri));
+ }
+
+ return new AccessDeniedException(outcome,
+ string.Format("Access to resource: {0} was denied, additional info: {1}",
+ uri, outcome.AdditionalInfo));
+ }
+
+ public static Exception ConsumerHasNotBeenGrantedAccessYet(IOAuthContext context)
+ {
+ return new OAuthException(context, OAuthProblems.PermissionUnknown,
+ "The decision to give access to the consumer has yet to be made, please try again later.");
+ }
+
+ public static Exception ConsumerHasBeenDeniedAccess(IOAuthContext context)
+ {
+ return new OAuthException(context, OAuthProblems.PermissionDenied,
+ "The consumer was denied access to this resource.");
+ }
+
+ public static Exception CantBuildProblemReportWhenProblemEmpty()
+ {
+ return new Exception("Can't build problem report when \"Problem\" property is null or empty");
+ }
+
+ public static Exception NonceHasAlreadyBeenUsed(IOAuthContext context)
+ {
+ return new OAuthException(context, OAuthProblems.NonceUsed,
+ string.Format("The nonce value \"{0}\" has already been used", context.Nonce));
+ }
+
+ public static Exception ThisConsumerRequestHasAlreadyBeenSigned()
+ {
+ return new Exception("The consumer request for consumer \"{0}\" has already been signed");
+ }
+ }
+}
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Specialized;
+
+namespace OAuth.Core.Interfaces
+{
+ public interface IOAuthContext : IToken
+ {
+ NameValueCollection Headers { get; set; }
+ NameValueCollection QueryParameters { get; set; }
+ NameValueCollection Cookies { get; set; }
+ NameValueCollection FormEncodedParameters { get; set; }
+ NameValueCollection AuthorizationHeaderParameters { get; set; }
+ Uri RawUri { get; set; }
+ string NormalizedRequestUrl { get; }
+ string RequestMethod { get; set; }
+ string Nonce { get; set; }
+ string Signature { get; set; }
+ string SignatureMethod { get; set; }
+ string Timestamp { get; set; }
+ string Version { get; set; }
+ string Verifier { get; set; }
+ string Callback { get; set; }
+ bool UseAuthorizationHeader { get; set; }
+
+ Uri GenerateUri();
+ string GenerateUrl();
+ string GenerateOAuthParametersForHeader();
+ Uri GenerateUriWithoutOAuthParameters();
+ string GenerateSignatureBase();
+ string ToString();
+ }
+}
@@ -0,0 +1,9 @@
+using System.Web;
+
+namespace OAuth.Core.Interfaces
+{
+ public interface IOAuthContextBuilder
+ {
+ IOAuthContext FromHttpRequest(HttpRequestBase request);
+ }
+}
@@ -0,0 +1,9 @@
+namespace OAuth.Core.Interfaces
+{
+ public interface IOAuthProvider
+ {
+ IToken GrantRequestToken(IOAuthContext authContext);
+ IToken ExchangeRequestTokenForAccessToken(IOAuthContext authContext);
+ void AccessProtectedResourceRequest(IOAuthContext authContext);
+ }
+}
@@ -0,0 +1,14 @@
+namespace OAuth.Core.Interfaces
+{
+ public interface IToken : IConsumer
+ {
+ string TokenSecret { get; set; }
+ string Token { get; set; }
+ }
+
+ public interface IConsumer
+ {
+ string ConsumerKey { get; set; }
+ string Realm { get; set; }
+ }
+}
Oops, something went wrong.

0 comments on commit 53b93d8

Please sign in to comment.