diff options
Diffstat (limited to 'src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs')
-rw-r--r-- | src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs index f25bcaa..f5e2d9c 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs @@ -11,6 +11,7 @@ namespace DotNetOpenAuth.OpenId { using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.ChannelElements; + using DotNetOpenAuth.OpenId.Messages; /// <summary> /// Provides the programmatic facilities to act as an OpenId consumer. @@ -27,5 +28,28 @@ namespace DotNetOpenAuth.OpenId { /// Gets the channel to use for sending/receiving messages. /// </summary> public Channel Channel { get; internal set; } + + /// <summary> + /// Gets an association between this Relying Party and a given Provider. + /// A new association is created if necessary and possible. + /// </summary> + /// <param name="provider">The provider to create an association with.</param> + /// <returns>The association if one exists and/or could be created. Null otherwise.</returns> + internal Association GetAssociation(ProviderEndpointDescription provider) { + ErrorUtilities.VerifyArgumentNotNull(provider, "provider"); + + var associateRequest = AssociateRequest.Create(provider); + var associateResponse = this.Channel.Request(associateRequest); + var associateSuccessfulResponse = associateResponse as AssociateSuccessfulResponse; + var associateUnsuccessfulResponse = associateResponse as AssociateUnsuccessfulResponse; + if (associateSuccessfulResponse != null) { + return associateSuccessfulResponse.CreateAssociation(associateRequest); + } else if (associateUnsuccessfulResponse != null) { + // TODO: code here + throw new NotImplementedException(); + } else { + throw new ProtocolException(MessagingStrings.UnexpectedMessageReceivedOfMany); + } + } } } |