summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj2
-rw-r--r--src/DotNetOpenAuth/OAuth2/AuthorizationState.cs1
-rw-r--r--src/DotNetOpenAuth/OAuth2/ClientBase.cs6
-rw-r--r--src/DotNetOpenAuth/OAuth2/IClientAuthorizationTracker.cs (renamed from src/DotNetOpenAuth/OAuth2/IClientTokenManager.cs)18
-rw-r--r--src/DotNetOpenAuth/OAuth2/WebServerClient.cs23
5 files changed, 31 insertions, 19 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 2b2a069..af24fa3 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -329,7 +329,7 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\IAccessTokenAnalyzer.cs" />
<Compile Include="OAuth2\IAuthorizationServer.cs" />
<Compile Include="OAuth2\IAuthorizationState.cs" />
- <Compile Include="OAuth2\IClientTokenManager.cs" />
+ <Compile Include="OAuth2\IClientAuthorizationTracker.cs" />
<Compile Include="OAuth2\IConsumerDescription.cs" />
<Compile Include="OAuth2\Messages\AccessProtectedResourceRequest.cs" />
<Compile Include="OAuth2\Messages\AccessTokenAssertionRequest.cs" />
diff --git a/src/DotNetOpenAuth/OAuth2/AuthorizationState.cs b/src/DotNetOpenAuth/OAuth2/AuthorizationState.cs
index b6d2ee5..907f6e7 100644
--- a/src/DotNetOpenAuth/OAuth2/AuthorizationState.cs
+++ b/src/DotNetOpenAuth/OAuth2/AuthorizationState.cs
@@ -10,6 +10,7 @@ namespace DotNetOpenAuth.OAuth2 {
/// <summary>
/// A simple memory-only copy of an authorization state.
/// </summary>
+ [Serializable]
public class AuthorizationState : IAuthorizationState {
/// <summary>
/// Initializes a new instance of the <see cref="AuthorizationState"/> class.
diff --git a/src/DotNetOpenAuth/OAuth2/ClientBase.cs b/src/DotNetOpenAuth/OAuth2/ClientBase.cs
index 9be1cee..a63fab3 100644
--- a/src/DotNetOpenAuth/OAuth2/ClientBase.cs
+++ b/src/DotNetOpenAuth/OAuth2/ClientBase.cs
@@ -24,10 +24,14 @@ namespace DotNetOpenAuth.OAuth2 {
/// Initializes a new instance of the <see cref="ClientBase"/> class.
/// </summary>
/// <param name="authorizationServer">The token issuer.</param>
- protected ClientBase(AuthorizationServerDescription authorizationServer) {
+ /// <param name="clientIdentifier">The client identifier.</param>
+ /// <param name="clientSecret">The client secret.</param>
+ protected ClientBase(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null) {
Contract.Requires<ArgumentNullException>(authorizationServer != null);
this.AuthorizationServer = authorizationServer;
this.Channel = new OAuthWrapAuthorizationServerChannel();
+ this.ClientIdentifier = clientIdentifier;
+ this.ClientSecret = clientSecret;
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OAuth2/IClientTokenManager.cs b/src/DotNetOpenAuth/OAuth2/IClientAuthorizationTracker.cs
index 776d691..97294e6 100644
--- a/src/DotNetOpenAuth/OAuth2/IClientTokenManager.cs
+++ b/src/DotNetOpenAuth/OAuth2/IClientAuthorizationTracker.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="IClientTokenManager.cs" company="Andrew Arnott">
+// <copyright file="IClientAuthorizationTracker.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -11,8 +11,8 @@ namespace DotNetOpenAuth.OAuth2 {
/// <summary>
/// A token manager implemented by some clients to assist in tracking authorization state.
/// </summary>
- [ContractClass(typeof(IClientTokenManagerContract))]
- public interface IClientTokenManager {
+ [ContractClass(typeof(IClientAuthorizationTrackerContract))]
+ public interface IClientAuthorizationTracker {
/// <summary>
/// Gets the state of the authorization for a given callback URL and client state.
/// </summary>
@@ -23,14 +23,14 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Contract class for the <see cref="IClientTokenManager"/> interface.
+ /// Contract class for the <see cref="IClientAuthorizationTracker"/> interface.
/// </summary>
- [ContractClassFor(typeof(IClientTokenManager))]
- internal abstract class IClientTokenManagerContract : IClientTokenManager {
+ [ContractClassFor(typeof(IClientAuthorizationTracker))]
+ internal abstract class IClientAuthorizationTrackerContract : IClientAuthorizationTracker {
/// <summary>
- /// Prevents a default instance of the <see cref="IClientTokenManagerContract"/> class from being created.
+ /// Prevents a default instance of the <see cref="IClientAuthorizationTrackerContract"/> class from being created.
/// </summary>
- private IClientTokenManagerContract() {
+ private IClientAuthorizationTrackerContract() {
}
#region IClientTokenManager Members
@@ -43,7 +43,7 @@ namespace DotNetOpenAuth.OAuth2 {
/// <returns>
/// The authorization state; may be <c>null</c> if no authorization state matches.
/// </returns>
- IAuthorizationState IClientTokenManager.GetAuthorizationState(Uri callbackUrl, string clientState) {
+ IAuthorizationState IClientAuthorizationTracker.GetAuthorizationState(Uri callbackUrl, string clientState) {
Contract.Requires<ArgumentNullException>(callbackUrl != null);
throw new NotImplementedException();
}
diff --git a/src/DotNetOpenAuth/OAuth2/WebServerClient.cs b/src/DotNetOpenAuth/OAuth2/WebServerClient.cs
index 1d98d7c..467d7d3 100644
--- a/src/DotNetOpenAuth/OAuth2/WebServerClient.cs
+++ b/src/DotNetOpenAuth/OAuth2/WebServerClient.cs
@@ -23,22 +23,25 @@ namespace DotNetOpenAuth.OAuth2 {
/// Initializes a new instance of the <see cref="WebServerClient"/> class.
/// </summary>
/// <param name="authorizationServer">The authorization server.</param>
- public WebServerClient(AuthorizationServerDescription authorizationServer)
- : base(authorizationServer) {
+ /// <param name="clientIdentifier">The client identifier.</param>
+ /// <param name="clientSecret">The client secret.</param>
+ public WebServerClient(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null)
+ : base(authorizationServer, clientIdentifier, clientSecret) {
}
/// <summary>
/// Gets or sets the token manager.
/// </summary>
/// <value>The token manager.</value>
- public IClientTokenManager TokenManager { get; set; }
+ public IClientAuthorizationTracker TokenManager { get; set; }
/// <summary>
/// Prepares a request for user authorization from an authorization server.
/// </summary>
/// <returns>The authorization request.</returns>
- public EndUserAuthorizationRequest PrepareRequestUserAuthorization() {
- return this.PrepareRequestUserAuthorization(new AuthorizationState());
+ public EndUserAuthorizationRequest PrepareRequestUserAuthorization(string scope = null) {
+ var authorizationState = new AuthorizationState { Scope = scope };
+ return this.PrepareRequestUserAuthorization(authorizationState);
}
/// <summary>
@@ -78,7 +81,6 @@ namespace DotNetOpenAuth.OAuth2 {
public IAuthorizationState ProcessUserAuthorization(HttpRequestInfo request = null) {
Contract.Requires<InvalidOperationException>(!string.IsNullOrEmpty(this.ClientIdentifier));
Contract.Requires<InvalidOperationException>(!string.IsNullOrEmpty(this.ClientSecret));
- Contract.Requires<InvalidOperationException>(this.TokenManager != null);
if (request == null) {
request = this.Channel.GetRequestFromContext();
@@ -87,8 +89,13 @@ namespace DotNetOpenAuth.OAuth2 {
IMessageWithClientState response;
if (this.Channel.TryReadFromRequest<IMessageWithClientState>(request, out response)) {
Uri callback = MessagingUtilities.StripMessagePartsFromQueryString(request.UrlBeforeRewriting, this.Channel.MessageDescriptions.Get(response));
- IAuthorizationState authorizationState = this.TokenManager.GetAuthorizationState(callback, response.ClientState);
- ErrorUtilities.VerifyProtocol(authorizationState != null, "Unexpected OAuth authorization response received with callback and client state that does not match an expected value.");
+ IAuthorizationState authorizationState;
+ if (this.TokenManager != null) {
+ authorizationState = this.TokenManager.GetAuthorizationState(callback, response.ClientState);
+ ErrorUtilities.VerifyProtocol(authorizationState != null, "Unexpected OAuth authorization response received with callback and client state that does not match an expected value.");
+ } else {
+ authorizationState = new AuthorizationState { Callback = callback };
+ }
var success = response as EndUserAuthorizationSuccessResponse;
var failure = response as EndUserAuthorizationFailedResponse;
ErrorUtilities.VerifyProtocol(success != null || failure != null, MessagingStrings.UnexpectedMessageReceivedOfMany);