本文整理汇总了C#中IDirectedProtocolMessage类的典型用法代码示例。如果您正苦于以下问题:C# IDirectedProtocolMessage类的具体用法?C# IDirectedProtocolMessage怎么用?C# IDirectedProtocolMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDirectedProtocolMessage类属于命名空间,在下文中一共展示了IDirectedProtocolMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewResponseMessage
/// <summary>
/// Analyzes an incoming request message payload to discover what kind of
/// message is embedded in it and returns the type, or null if no match is found.
/// </summary>
/// <param name="request">
/// The message that was sent as a request that resulted in the response.
/// Null on a Consumer site that is receiving an indirect message from the Service Provider.
/// </param>
/// <param name="fields">The name/value pairs that make up the message payload.</param>
/// <returns>
/// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
/// deserialize to. Null if the request isn't recognized as a valid protocol message.
/// </returns>
/// <remarks>
/// The response messages are:
/// UnauthorizedTokenResponse
/// AuthorizedTokenResponse
/// </remarks>
public virtual IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
MessageBase message = null;
// All response messages have the oauth_token field.
if (!fields.ContainsKey("oauth_token")) {
return null;
}
// All direct message responses should have the oauth_token_secret field.
if (!fields.ContainsKey("oauth_token_secret")) {
Logger.OAuth.Error("An OAuth message was expected to contain an oauth_token_secret but didn't.");
return null;
}
var unauthorizedTokenRequest = request as UnauthorizedTokenRequest;
var authorizedTokenRequest = request as AuthorizedTokenRequest;
if (unauthorizedTokenRequest != null) {
Protocol protocol = fields.ContainsKey("oauth_callback_confirmed") ? Protocol.V10a : Protocol.V10;
message = new UnauthorizedTokenResponse(unauthorizedTokenRequest, protocol.Version);
} else if (authorizedTokenRequest != null) {
message = new AuthorizedTokenResponse(authorizedTokenRequest);
} else {
Logger.OAuth.ErrorFormat("Unexpected response message given the request type {0}", request.GetType().Name);
throw new ProtocolException(OAuthStrings.InvalidIncomingMessage);
}
if (message != null) {
message.SetAsIncoming();
}
return message;
}
示例2: TryValidateAccessToken
/// <summary>
/// Reads an access token to find out what data it authorizes access to.
/// </summary>
/// <param name="message">The message carrying the access token.</param>
/// <param name="accessToken">The access token.</param>
/// <param name="user">The user whose data is accessible with this access token.</param>
/// <param name="scope">The scope of access authorized by this access token.</param>
/// <returns>
/// A value indicating whether this access token is valid.
/// </returns>
/// <remarks>
/// This method also responsible to throw a <see cref="ProtocolException"/> or return
/// <c>false</c> when the access token is expired, invalid, or from an untrusted authorization server.
/// </remarks>
public virtual bool TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope) {
var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServerPublicSigningKey, this.ResourceServerPrivateEncryptionKey);
var token = accessTokenFormatter.Deserialize(message, accessToken);
user = token.User;
scope = new HashSet<string>(token.Scope, OAuthUtilities.ScopeStringComparer);
return true;
}
示例3: AutoResponsiveRequest
/// <summary>
/// Initializes a new instance of the <see cref="AutoResponsiveRequest"/> class.
/// </summary>
/// <param name="request">The request message.</param>
/// <param name="response">The response that is ready for transmittal.</param>
internal AutoResponsiveRequest(IDirectedProtocolMessage request, IProtocolMessage response)
: base(request)
{
ErrorUtilities.VerifyArgumentNotNull(response, "response");
this.response = response;
}
示例4: NotImplementedException
/// <summary>
/// Reads an access token to find out what data it authorizes access to.
/// </summary>
/// <param name="message">The message carrying the access token.</param>
/// <param name="accessToken">The access token.</param>
/// <param name="user">The user whose data is accessible with this access token.</param>
/// <param name="scope">The scope of access authorized by this access token.</param>
/// <returns>
/// A value indicating whether this access token is valid.
/// </returns>
bool IAccessTokenAnalyzer.TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope) {
Requires.NotNull(message, "message");
Requires.NotNullOrEmpty(accessToken, "accessToken");
Contract.Ensures(Contract.Result<bool>() == (Contract.ValueAtReturn<string>(out user) != null));
throw new NotImplementedException();
}
示例5: AutoResponsiveRequest
/// <summary>
/// Initializes a new instance of the <see cref="AutoResponsiveRequest"/> class.
/// </summary>
/// <param name="request">The request message.</param>
/// <param name="response">The response that is ready for transmittal.</param>
/// <param name="securitySettings">The security settings.</param>
internal AutoResponsiveRequest(IDirectedProtocolMessage request, IProtocolMessage response, ProviderSecuritySettings securitySettings)
: base(request, securitySettings)
{
ErrorUtilities.VerifyArgumentNotNull(response, "response");
this.response = response;
}
示例6: MessageBase
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class for direct response messages.
/// </summary>
/// <param name="protectionRequired">The level of protection the message requires.</param>
/// <param name="originatingRequest">The request that asked for this direct response.</param>
protected MessageBase(MessageProtections protectionRequired, IDirectedProtocolMessage originatingRequest)
{
ErrorUtilities.VerifyArgumentNotNull(originatingRequest, "originatingRequest");
this.protectionRequired = protectionRequired;
this.transport = MessageTransport.Direct;
this.originatingRequest = originatingRequest;
}
示例7: MessageBase
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class.
/// </summary>
/// <param name="request">The originating request.</param>
/// <param name="recipient">The recipient of the directed message. Null if not applicable.</param>
protected MessageBase(IDirectedProtocolMessage request, Uri recipient = null) {
Requires.NotNull(request, "request");
this.originatingRequest = request;
this.messageTransport = request.Transport;
this.version = request.Version;
this.Recipient = recipient;
this.HttpMethods = HttpDeliveryMethods.GetRequest;
}
示例8: MessageBase
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class.
/// </summary>
/// <param name="request">The originating request.</param>
/// <param name="recipient">The recipient of the directed message. Null if not applicable.</param>
protected MessageBase(IDirectedProtocolMessage request, Uri recipient = null) {
Contract.Requires<ArgumentNullException>(request != null);
this.originatingRequest = request;
this.messageTransport = request.Transport;
this.version = request.Version;
this.Recipient = recipient;
this.HttpMethods = HttpDeliveryMethods.GetRequest;
}
示例9: MessageBase
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class for direct response messages.
/// </summary>
/// <param name="protectionRequired">The level of protection the message requires.</param>
/// <param name="originatingRequest">The request that asked for this direct response.</param>
/// <param name="version">The OAuth version.</param>
protected MessageBase(MessageProtections protectionRequired, IDirectedProtocolMessage originatingRequest, Version version) {
Requires.NotNull(originatingRequest, "originatingRequest");
Requires.NotNull(version, "version");
this.protectionRequired = protectionRequired;
this.transport = MessageTransport.Direct;
this.originatingRequest = originatingRequest;
this.Version = version;
}
示例10: MessageBase
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class for direct response messages.
/// </summary>
/// <param name="protectionRequired">The level of protection the message requires.</param>
/// <param name="originatingRequest">The request that asked for this direct response.</param>
/// <param name="version">The OAuth version.</param>
protected MessageBase(MessageProtections protectionRequired, IDirectedProtocolMessage originatingRequest, Version version) {
Contract.Requires<ArgumentNullException>(originatingRequest != null);
Contract.Requires<ArgumentNullException>(version != null);
this.protectionRequired = protectionRequired;
this.transport = MessageTransport.Direct;
this.originatingRequest = originatingRequest;
this.Version = version;
}
示例11: CreateHttpRequest
/// <summary>
/// Prepares an HTTP request that carries a given message.
/// </summary>
/// <param name="request">The message to send.</param>
/// <returns>
/// The <see cref="HttpWebRequest"/> prepared to send the request.
/// </returns>
/// <remarks>
/// This method must be overridden by a derived class, unless the <see cref="Channel.RequestCore"/> method
/// is overridden and does not require this method.
/// </remarks>
protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
HttpWebRequest httpRequest;
if ((request.HttpMethods & HttpDeliveryMethods.GetRequest) != 0) {
httpRequest = InitializeRequestAsGet(request);
} else if ((request.HttpMethods & HttpDeliveryMethods.PostRequest) != 0) {
httpRequest = InitializeRequestAsPost(request);
} else {
throw new NotSupportedException();
}
return httpRequest;
}
示例12: DeserializeAccessToken
/// <summary>
/// Reads an access token to find out what data it authorizes access to.
/// </summary>
/// <param name="message">The message carrying the access token.</param>
/// <param name="accessToken">The access token's serialized representation.</param>
/// <returns>The deserialized, validated token.</returns>
/// <exception cref="ProtocolException">Thrown if the access token is expired, invalid, or from an untrusted authorization server.</exception>
public virtual AccessToken DeserializeAccessToken(IDirectedProtocolMessage message, string accessToken) {
ErrorUtilities.VerifyProtocol(!string.IsNullOrEmpty(accessToken), ResourceServerStrings.MissingAccessToken);
var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServerPublicSigningKey, this.ResourceServerPrivateEncryptionKey);
var token = new AccessToken();
try {
accessTokenFormatter.Deserialize(token, accessToken, message, Protocol.access_token);
} catch (IOException ex) {
throw new ProtocolException(ResourceServerStrings.InvalidAccessToken, ex);
}
return token;
}
示例13: GetNewResponseMessage
/// <summary>
/// Analyzes an incoming request message payload to discover what kind of
/// message is embedded in it and returns the type, or null if no match is found.
/// </summary>
/// <param name="request">The message that was sent as a request that resulted in the response.</param>
/// <param name="fields">The name/value pairs that make up the message payload.</param>
/// <returns>
/// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
/// deserialize to. Null if the request isn't recognized as a valid protocol message.
/// </returns>
public IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
DirectResponseBase message = null;
// Discern the OpenID version of the message.
Protocol protocol = Protocol.V11;
string ns;
if (fields.TryGetValue(Protocol.V20.openidnp.ns, out ns)) {
ErrorUtilities.VerifyProtocol(string.Equals(ns, Protocol.OpenId2Namespace, StringComparison.Ordinal), MessagingStrings.UnexpectedMessagePartValue, Protocol.V20.openidnp.ns, ns);
protocol = Protocol.V20;
}
// Handle error messages generally.
if (fields.ContainsKey(protocol.openidnp.error)) {
message = new DirectErrorResponse(protocol.Version, request);
}
var associateRequest = request as AssociateRequest;
if (associateRequest != null) {
if (protocol.Version.Major >= 2 && fields.ContainsKey(protocol.openidnp.error_code)) {
// This is a special recognized error case that we create a special message for.
message = new AssociateUnsuccessfulResponse(protocol.Version, associateRequest);
} else if (message == null) {
if (OpenIdUtilities.IsDiffieHellmanPresent) {
var associateDiffieHellmanRequest = request as AssociateDiffieHellmanRequest;
if (associateDiffieHellmanRequest != null) {
message = new AssociateDiffieHellmanRelyingPartyResponse(protocol.Version, associateDiffieHellmanRequest);
}
}
var associateUnencryptedRequest = request as AssociateUnencryptedRequest;
if (associateUnencryptedRequest != null) {
message = new AssociateUnencryptedResponseRelyingParty(protocol.Version, associateUnencryptedRequest);
}
}
}
var checkAuthenticationRequest = request as CheckAuthenticationRequest;
if (checkAuthenticationRequest != null && message == null) {
message = new CheckAuthenticationResponse(protocol.Version, checkAuthenticationRequest);
}
if (message != null) {
message.SetAsIncoming();
}
return message;
}
示例14: NotImplementedException
/// <summary>
/// Analyzes an incoming request message payload to discover what kind of
/// message is embedded in it and returns the type, or null if no match is found.
/// </summary>
/// <param name="request">The message that was sent as a request that resulted in the response.</param>
/// <param name="fields">The name/value pairs that make up the message payload.</param>
/// <returns>
/// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
/// deserialize to. Null if the request isn't recognized as a valid protocol message.
/// </returns>
IDirectResponseProtocolMessage IMessageFactory.GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
Requires.NotNull(request, "request");
Requires.NotNull(fields, "fields");
throw new NotImplementedException();
}
示例15: CreateHttpRequest
protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
throw new NotImplementedException("CreateHttpRequest");
}