summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth/ClassDiagram.cd63
-rw-r--r--src/DotNetOAuth/DotNetOAuth.csproj3
-rw-r--r--src/DotNetOAuth/Messaging/HttpRequestInfo.cs16
-rw-r--r--src/DotNetOAuth/ServiceProvider.cs96
4 files changed, 108 insertions, 70 deletions
diff --git a/src/DotNetOAuth/ClassDiagram.cd b/src/DotNetOAuth/ClassDiagram.cd
index 1219a22..f4db17c 100644
--- a/src/DotNetOAuth/ClassDiagram.cd
+++ b/src/DotNetOAuth/ClassDiagram.cd
@@ -1,73 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="DotNetOAuth.ServiceProvider">
- <Position X="0.5" Y="0.5" Width="2" />
+ <Position X="0.5" Y="0.5" Width="3.5" />
<TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAACAAAACAAAAAAAAAAAAABAAAAAQ=</HashCode>
+ <HashCode>EAoAAAAgAAACAAABCAAEAAAAAAAIAAEAAQAIAAAAAQA=</HashCode>
<FileName>ServiceProvider.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOAuth.Consumer">
- <Position X="2.75" Y="0.5" Width="1.75" />
+ <Position X="4.25" Y="0.5" Width="3" />
<TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>AAAAAAAgAAABEAAAAIAABgAAACAIAAQAAYAAAAAAAAA=</HashCode>
<FileName>Consumer.cs</FileName>
</TypeIdentifier>
</Class>
- <Class Name="DotNetOAuth.DirectMessageChannel">
- <Position X="5" Y="2.75" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>DirectMessageChannel.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.IndirectMessageEncoder">
- <Position X="5" Y="4" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>IndirectMessageEncoder.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.IndirectMessage" Collapsed="true">
- <Position X="5" Y="5.25" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAEAABAAAAAAEABAAAACAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>IndirectMessage.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Class Name="DotNetOAuth.ProtocolMessageSerializer&lt;T&gt;">
- <Position X="5" Y="0.5" Width="2.25" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAIAAAAAAAAAAAAAAEACBAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>ProtocolMessageSerializer.cs</FileName>
- </TypeIdentifier>
- </Class>
- <Interface Name="DotNetOAuth.IProtocolMessage">
- <Position X="2.75" Y="1.5" Width="1.75" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAQAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>IProtocolMessage.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOAuth.IProtocolMessageRequest">
- <Position X="2.75" Y="3.25" Width="1.75" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>IProtocolMessageRequest.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Enum Name="DotNetOAuth.MessageScheme">
- <Position X="0.5" Y="2.75" Width="2" />
- <TypeIdentifier>
- <HashCode>AQAAAAAAAAAAAAIAAAAAAACAAAAAAAgAAAAAAAAAAAA=</HashCode>
- <FileName>MessageScheme.cs</FileName>
- </TypeIdentifier>
- </Enum>
- <Enum Name="DotNetOAuth.MessageTransport">
- <Position X="0.5" Y="4.5" Width="1.75" />
+ <Enum Name="DotNetOAuth.Messaging.MessageTransport">
+ <Position X="0.5" Y="4.5" Width="2" />
<TypeIdentifier>
<HashCode>AAACAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>MessageTransport.cs</FileName>
+ <FileName>Messaging\MessageTransport.cs</FileName>
</TypeIdentifier>
</Enum>
<Font Name="Segoe UI" Size="9" />
diff --git a/src/DotNetOAuth/DotNetOAuth.csproj b/src/DotNetOAuth/DotNetOAuth.csproj
index 0dd6d15..bb8fe2d 100644
--- a/src/DotNetOAuth/DotNetOAuth.csproj
+++ b/src/DotNetOAuth/DotNetOAuth.csproj
@@ -53,6 +53,9 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
+ <Reference Include="System.ServiceModel">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
<Reference Include="System.Web" />
<Reference Include="System.XML" />
</ItemGroup>
diff --git a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
index af0e637..efd9dec 100644
--- a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
+++ b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
@@ -10,6 +10,7 @@ namespace DotNetOAuth.Messaging {
using System.Diagnostics;
using System.IO;
using System.Net;
+ using System.ServiceModel.Channels;
using System.Web;
/// <summary>
@@ -62,6 +63,21 @@ namespace DotNetOAuth.Messaging {
/// <summary>
/// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
/// </summary>
+ /// <param name="request">The WCF incoming request structure to get the HTTP information from.</param>
+ /// <param name="requestUri">The URI of the service endpoint.</param>
+ internal HttpRequestInfo(HttpRequestMessageProperty request, Uri requestUri) {
+ if (request == null) {
+ throw new ArgumentNullException("request");
+ }
+
+ this.HttpMethod = request.Method;
+ this.Headers = request.Headers;
+ this.Url = requestUri;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HttpRequestInfo"/> class.
+ /// </summary>
/// <param name="request">The HttpWebRequest (that was never used) to copy from.</param>
internal HttpRequestInfo(WebRequest request) {
this.HttpMethod = request.Method;
diff --git a/src/DotNetOAuth/ServiceProvider.cs b/src/DotNetOAuth/ServiceProvider.cs
index c786c47..513ab35 100644
--- a/src/DotNetOAuth/ServiceProvider.cs
+++ b/src/DotNetOAuth/ServiceProvider.cs
@@ -8,6 +8,7 @@ namespace DotNetOAuth {
using System;
using System.Collections.Generic;
using System.Globalization;
+ using System.ServiceModel.Channels;
using System.Web;
using DotNetOAuth.ChannelElements;
using DotNetOAuth.Messages;
@@ -69,6 +70,23 @@ namespace DotNetOAuth {
internal OAuthChannel Channel { get; set; }
/// <summary>
+ /// Reads any incoming OAuth message.
+ /// </summary>
+ /// <returns>The deserialized message.</returns>
+ public IProtocolMessage ReadRequest() {
+ return this.Channel.ReadFromRequest();
+ }
+
+ /// <summary>
+ /// Reads any incoming OAuth message.
+ /// </summary>
+ /// <param name="request">The HTTP request to read the message from.</param>
+ /// <returns>The deserialized message.</returns>
+ public IProtocolMessage ReadRequest(HttpRequest request) {
+ return this.Channel.ReadFromRequest(new HttpRequestInfo(request));
+ }
+
+ /// <summary>
/// Gets the incoming request for an unauthorized token, if any.
/// </summary>
/// <returns>The incoming request, or null if no OAuth message was attached.</returns>
@@ -77,7 +95,7 @@ namespace DotNetOAuth {
/// Requires HttpContext.Current.
/// </remarks>
public RequestTokenMessage ReadTokenRequest() {
- return this.Channel.ReadFromRequest<RequestTokenMessage>();
+ return this.ReadTokenRequest(this.Channel.GetRequestFromContext());
}
/// <summary>
@@ -95,7 +113,7 @@ namespace DotNetOAuth {
/// for subsequent authorization.
/// </summary>
/// <param name="request">The token request message the Consumer sent that the Service Provider is now responding to.</param>
- /// <param name="extraParameters">Any extra parameters the Consumer should receive with the OAuth message.</param>
+ /// <param name="extraParameters">Any extra parameters the Consumer should receive with the OAuth message. May be null.</param>
/// <returns>The actual response the Service Provider will need to forward as the HTTP response.</returns>
public Response SendUnauthorizedTokenResponse(RequestTokenMessage request, IDictionary<string, string> extraParameters) {
string token = this.TokenGenerator.GenerateRequestToken(request.ConsumerKey);
@@ -183,7 +201,7 @@ namespace DotNetOAuth {
/// Prepares and sends an access token to a Consumer, and invalidates the request token.
/// </summary>
/// <param name="request">The Consumer's message requesting an access token.</param>
- /// <param name="extraParameters">Any extra parameters the Service Provider wishes to send to the Consumer.</param>
+ /// <param name="extraParameters">Any extra parameters the Consumer should receive with the OAuth message. May be null.</param>
/// <returns>The HTTP response to actually send to the Consumer.</returns>
public Response SendAccessToken(RequestAccessTokenMessage request, IDictionary<string, string> extraParameters) {
if (request == null) {
@@ -221,18 +239,38 @@ namespace DotNetOAuth {
/// </remarks>
/// <exception cref="ProtocolException">Thrown if an unexpected message is attached to the request.</exception>
public AccessProtectedResourcesMessage GetProtectedResourceAuthorization() {
- AccessProtectedResourcesMessage accessMessage;
- if (this.Channel.TryReadFromRequest<AccessProtectedResourcesMessage>(out accessMessage)) {
- if (this.TokenManager.GetTokenType(accessMessage.AccessToken) != TokenType.AccessToken) {
- throw new ProtocolException(
- string.Format(
- CultureInfo.CurrentCulture,
- Strings.BadAccessTokenInProtectedResourceRequest,
- accessMessage.AccessToken));
- }
- }
+ return this.GetProtectedResourceAuthorization(this.Channel.GetRequestFromContext());
+ }
- return accessMessage;
+ /// <summary>
+ /// Gets the authorization (access token) for accessing some protected resource.
+ /// </summary>
+ /// <param name="request">The incoming HTTP request.</param>
+ /// <returns>The authorization message sent by the Consumer, or null if no authorization message is attached.</returns>
+ /// <remarks>
+ /// This method verifies that the access token and token secret are valid.
+ /// It falls on the caller to verify that the access token is actually authorized
+ /// to access the resources being requested.
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if an unexpected message is attached to the request.</exception>
+ public AccessProtectedResourcesMessage GetProtectedResourceAuthorization(HttpRequest request) {
+ return this.GetProtectedResourceAuthorization(new HttpRequestInfo(request));
+ }
+
+ /// <summary>
+ /// Gets the authorization (access token) for accessing some protected resource.
+ /// </summary>
+ /// <param name="request">HTTP details from an incoming WCF message.</param>
+ /// <param name="requestUri">The URI of the WCF service endpoint.</param>
+ /// <returns>The authorization message sent by the Consumer, or null if no authorization message is attached.</returns>
+ /// <remarks>
+ /// This method verifies that the access token and token secret are valid.
+ /// It falls on the caller to verify that the access token is actually authorized
+ /// to access the resources being requested.
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if an unexpected message is attached to the request.</exception>
+ public AccessProtectedResourcesMessage GetProtectedResourceAuthorization(HttpRequestMessageProperty request, Uri requestUri) {
+ return this.GetProtectedResourceAuthorization(new HttpRequestInfo(request, requestUri));
}
/// <summary>
@@ -273,6 +311,36 @@ namespace DotNetOAuth {
}
/// <summary>
+ /// Gets the authorization (access token) for accessing some protected resource.
+ /// </summary>
+ /// <param name="request">The incoming HTTP request.</param>
+ /// <returns>The authorization message sent by the Consumer, or null if no authorization message is attached.</returns>
+ /// <remarks>
+ /// This method verifies that the access token and token secret are valid.
+ /// It falls on the caller to verify that the access token is actually authorized
+ /// to access the resources being requested.
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if an unexpected message is attached to the request.</exception>
+ internal AccessProtectedResourcesMessage GetProtectedResourceAuthorization(HttpRequestInfo request) {
+ if (request == null) {
+ throw new ArgumentNullException("request");
+ }
+
+ AccessProtectedResourcesMessage accessMessage;
+ if (this.Channel.TryReadFromRequest<AccessProtectedResourcesMessage>(request, out accessMessage)) {
+ if (this.TokenManager.GetTokenType(accessMessage.AccessToken) != TokenType.AccessToken) {
+ throw new ProtocolException(
+ string.Format(
+ CultureInfo.CurrentCulture,
+ Strings.BadAccessTokenInProtectedResourceRequest,
+ accessMessage.AccessToken));
+ }
+ }
+
+ return accessMessage;
+ }
+
+ /// <summary>
/// Fills out the secrets in an incoming message so that signature verification can be performed.
/// </summary>
/// <param name="message">The incoming message.</param>