summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs28
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs (renamed from src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs)19
-rw-r--r--src/DotNetOpenAuth/OpenId/OpenIdProvider.cs42
-rw-r--r--src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs14
5 files changed, 83 insertions, 22 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index e3c984c..1bc5355 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -104,7 +104,7 @@
<Compile Include="OpenId\Messages\DirectErrorResponseTests.cs" />
<Compile Include="OpenId\Messages\IndirectErrorResponseTests.cs" />
<Compile Include="OpenId\OpenIdCoordinator.cs" />
- <Compile Include="OpenId\ScenarioTests.cs" />
+ <Compile Include="OpenId\OpenIdScenarioTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Messaging\ResponseTests.cs" />
<Compile Include="OAuth\AppendixScenarios.cs" />
diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
index 6ec2f38..4c3312b 100644
--- a/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
@@ -17,19 +17,31 @@ namespace DotNetOpenAuth.Test.OpenId {
: base(rpAction, opAction) {
}
- internal override void Run() {
- OpenIdRelyingParty rp = new OpenIdRelyingParty();
- OpenIdProvider op = new OpenIdProvider();
+ internal OpenIdProvider Provider { get; set; }
+
+ internal OpenIdRelyingParty RelyingParty { get; set; }
- var rpCoordinatingChannel = new CoordinatingChannel(rp.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
- var opCoordinatingChannel = new CoordinatingChannel(op.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
+ internal override void Run() {
+ this.EnsurePartiesAreInitialized();
+ var rpCoordinatingChannel = new CoordinatingChannel(this.RelyingParty.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
+ var opCoordinatingChannel = new CoordinatingChannel(this.Provider.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
rpCoordinatingChannel.RemoteChannel = opCoordinatingChannel;
opCoordinatingChannel.RemoteChannel = rpCoordinatingChannel;
- rp.Channel = rpCoordinatingChannel;
- op.Channel = opCoordinatingChannel;
+ this.RelyingParty.Channel = rpCoordinatingChannel;
+ this.Provider.Channel = opCoordinatingChannel;
+
+ RunCore(this.RelyingParty, this.Provider);
+ }
+
+ private void EnsurePartiesAreInitialized() {
+ if (this.RelyingParty == null) {
+ this.RelyingParty = new OpenIdRelyingParty(new AssociationMemoryStore<Uri>());
+ }
- RunCore(rp, op);
+ if (this.Provider == null) {
+ this.Provider = new OpenIdProvider(new AssociationMemoryStore<AssociationRelyingPartyType>());
+ }
}
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs
index ddcae42..62982bd 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="ScenarioTests.cs" company="Andrew Arnott">
+// <copyright file="OpenIdScenarioTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -15,26 +15,22 @@ namespace DotNetOpenAuth.Test.OpenId {
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
- public class ScenarioTests {
+ public class OpenIdScenarioTests {
private readonly Protocol Protocol = Protocol.V20;
[TestMethod]
public void AssociateDiffieHellmanMessages() {
- Association rpAssociation = null, opAssociation = null;
+ Association rpAssociation = null, opAssociation;
AssociateDiffieHellmanResponse associateResponse = null;
+ var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol);
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var op = new ProviderEndpointDescription(new Uri("http://host"), Protocol);
- rpAssociation = rp.GetAssociation(op);
+ rpAssociation = rp.GetAssociation(opDescription);
Assert.IsNotNull(rpAssociation);
Assert.IsFalse(MessagingUtilities.AreEquivalent(associateResponse.EncodedMacKey, rpAssociation.SecretKey), "Key should have been encrypted.");
},
op => {
- var associateRequest = op.Channel.ReadFromRequest<AssociateDiffieHellmanRequest>();
- var response = new AssociateDiffieHellmanResponse();
- response.AssociationType = associateRequest.AssociationType;
- opAssociation = response.CreateAssociation(associateRequest);
- op.Channel.Send(response);
+ op.AutoRespond();
});
coordinator.IncomingMessageFilter = (message) => {
var associateResponseMessage = message as AssociateDiffieHellmanResponse;
@@ -44,6 +40,9 @@ namespace DotNetOpenAuth.Test.OpenId {
}
};
coordinator.Run();
+ Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle));
+ opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle);
+ Assert.IsNotNull(opAssociation, "The Provider should have stored the association.");
Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60);
Assert.IsTrue(MessagingUtilities.AreEquivalent(opAssociation.SecretKey, rpAssociation.SecretKey));
diff --git a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs
index 6f6c899..8902233 100644
--- a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs
+++ b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs
@@ -11,6 +11,7 @@ namespace DotNetOpenAuth.OpenId {
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.ChannelElements;
+ using DotNetOpenAuth.OpenId.Messages;
/// <summary>
/// Offers services for a web page that is acting as an OpenID identity server.
@@ -19,13 +20,52 @@ namespace DotNetOpenAuth.OpenId {
/// <summary>
/// Initializes a new instance of the <see cref="OpenIdProvider"/> class.
/// </summary>
- public OpenIdProvider() {
+ /// <param name="associationStore">The association store to use. Cannot be null.</param>
+ public OpenIdProvider(IAssociationStore<AssociationRelyingPartyType> associationStore) {
+ ErrorUtilities.VerifyArgumentNotNull(associationStore, "associationStore");
+
this.Channel = new OpenIdChannel();
+ this.AssociationStore = associationStore;
}
/// <summary>
/// Gets the channel to use for sending/receiving messages.
/// </summary>
public Channel Channel { get; internal set; }
+
+ /// <summary>
+ /// Gets the association store.
+ /// </summary>
+ internal IAssociationStore<AssociationRelyingPartyType> AssociationStore { get; private set; }
+
+ /// <summary>
+ /// Responds automatically to the incoming message.
+ /// </summary>
+ /// <remarks>
+ /// The design of a method like this is flawed... but it helps us get tests going for now.
+ /// </remarks>
+ internal void AutoRespond() {
+ var request = this.Channel.ReadFromRequest();
+
+ var associateRequest = request as AssociateRequest;
+ if (associateRequest != null) {
+ var associateDiffieHellmanRequest = request as AssociateDiffieHellmanRequest;
+
+ AssociateSuccessfulResponse response;
+ if (associateDiffieHellmanRequest != null) {
+ response = new AssociateDiffieHellmanResponse();
+ } else {
+ // TODO: code here
+ throw new NotImplementedException();
+ }
+ response.AssociationType = associateDiffieHellmanRequest.AssociationType;
+ Association association = response.CreateAssociation(associateRequest);
+ this.AssociationStore.StoreAssociation(AssociationRelyingPartyType.Smart, association);
+ this.Channel.Send(response);
+ } else {
+ // TODO: code here
+ throw new NotImplementedException();
+ }
+ }
}
}
diff --git a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs
index f5e2d9c..af239b1 100644
--- a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs
+++ b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs
@@ -20,8 +20,11 @@ namespace DotNetOpenAuth.OpenId {
/// <summary>
/// Initializes a new instance of the <see cref="OpenIdRelyingParty"/> class.
/// </summary>
- public OpenIdRelyingParty() {
+ public OpenIdRelyingParty(IAssociationStore<Uri> associationStore) {
+ ErrorUtilities.VerifyArgumentNotNull(associationStore, "associationStore");
+
this.Channel = new OpenIdChannel();
+ this.AssociationStore = associationStore;
}
/// <summary>
@@ -30,6 +33,11 @@ namespace DotNetOpenAuth.OpenId {
public Channel Channel { get; internal set; }
/// <summary>
+ /// Gets the association store.
+ /// </summary>
+ internal IAssociationStore<Uri> AssociationStore { get; private set; }
+
+ /// <summary>
/// Gets an association between this Relying Party and a given Provider.
/// A new association is created if necessary and possible.
/// </summary>
@@ -43,7 +51,9 @@ namespace DotNetOpenAuth.OpenId {
var associateSuccessfulResponse = associateResponse as AssociateSuccessfulResponse;
var associateUnsuccessfulResponse = associateResponse as AssociateUnsuccessfulResponse;
if (associateSuccessfulResponse != null) {
- return associateSuccessfulResponse.CreateAssociation(associateRequest);
+ Association association = associateSuccessfulResponse.CreateAssociation(associateRequest);
+ this.AssociationStore.StoreAssociation(provider.Endpoint, association);
+ return association;
} else if (associateUnsuccessfulResponse != null) {
// TODO: code here
throw new NotImplementedException();