вам удалось по реализации JWT на SilverLight приложение?
Update
На мой код клиента SilverLight, я добавляю в JWT маркер в заголовок авторизации HTTP, для каждого запроса. Чтобы добавить заголовок, я создал поведение (AttachRequestInformationEndpointBehavior), которое отвечает за это. Следующий код добавляет поведение в ExampleDomainContext:
Partial Class ExampleDomainContext
Private Sub OnCreated()
Dim channelFactoryProperty As PropertyInfo = Me.DomainClient.GetType().GetProperty("ChannelFactory")
If (channelFactoryProperty IsNot Nothing) Then
Dim factory = TryCast(channelFactoryProperty.GetValue(Me.DomainClient, Nothing), channelFactory)
If factory IsNot Nothing Then
If Not factory.Endpoint.Behaviors.Contains(GetType(Infrastructure.WebServices.AttachRequestInformationEndpointBehavior)) Then
factory.Endpoint.Behaviors.Add(New Wintouch.Infrastructure.WebServices.AttachRequestInformationEndpointBehavior())
End If
End If
End If
End Sub
End Class
Если следует код поведения:
Public Class AttachRequestInformationEndpointBehavior
Implements IEndpointBehavior, IClientMessageInspector
Public Sub AddBindingParameters(endpoint As ServiceEndpoint, bindingParameters As BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters
End Sub
Public Sub ApplyClientBehavior(endpoint As ServiceEndpoint, clientRuntime As System.ServiceModel.Dispatcher.ClientRuntime) Implements IEndpointBehavior.ApplyClientBehavior
clientRuntime.MessageInspectors.Add(Me)
End Sub
Public Sub ApplyDispatchBehavior(endpoint As ServiceEndpoint, endpointDispatcher As System.ServiceModel.Dispatcher.EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior
End Sub
Public Sub Validate(endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate
End Sub
Public Sub AfterReceiveReply(ByRef reply As Message, correlationState As Object) Implements IClientMessageInspector.AfterReceiveReply
End Sub
Public Function BeforeSendRequest(ByRef request As Message, channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest
Dim header As HttpRequestMessageProperty
If request.Properties.ContainsKey(HttpRequestMessageProperty.Name) Then
header = CType(request.Properties(HttpRequestMessageProperty.Name), HttpRequestMessageProperty)
Else
header = New HttpRequestMessageProperty()
request.Properties.Add(HttpRequestMessageProperty.Name, header)
End If
header.Headers("Authorization") = "Bearer " + "the user token here..."
Return Nothing
End Function
На стороне сервера, я просто заполнить HttpContext.Current.User и тему. CurrentPrincipal с информацией, извлеченной из токена. Например:
В Global.asax файл:
protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
// code to read the token
var tokenHandler = new TokenHandler();
// get the token from the http request header
var authHeaders = Request.Headers.GetValues("Authorization");
if (authHeaders == null || authHeaders.Length < 1) return;
var authHeader = authHeaders[0].Split(' ');
var scheme = authHeader[0];
var tokenString = authHeader[1];
if (scheme != "Bearer") return;
// retrieves the principal from the token
IPrincipal principal = tokenHandler.ReadPrincipal(tokenString);
// set the relevant variables
Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
}
Нет, Успех в далеко реализовать JWT маркер в Silverlight – Chirag
Чираг, я на самом деле сделал это. Для каждой службы домена я создал перехватчик, который добавляет токен jwt в заголовок http. Затем, на сервере, я прочитал токен и установил Принципала. Если вы хотите увидеть мой код, я могу отправить вас. – cangosta
Привет, Cangosta, спасибо за сообщение, пожалуйста, отправьте код мне на мой адрес электронной почты chi[email protected] – Chirag