カスタム認証応答を返すことはできますか?私はすでにCredentialsAuthProviderから継承した独自のカスタム認証プロバイダを持っています。ServiceStack認証からカスタム認証応答オブジェクトを返す
私は、クライアントが自分のサーバーセッションが期限切れになるときを正確に知っているように、応答セッション有効期限を返したい:
public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
{
// get base response
var response = base.Authenticate(authService, session, request);
// grab the session
var customSession = authService.GetSession() as CustomUserSession;
// if response can be cast and customSession exists
if (response is AuthResponse && customSession != null)
{
// cast
var authResponse = response as AuthResponse;
// build custom response
var customAuthResponse = new CustomAuthResponse
{
ReferrerUrl = authResponse.ReferrerUrl,
SessionExpiry = customSession.SessionExpires,
SessionId = authResponse.SessionId,
ResponseStatus = authResponse.ResponseStatus,
UserName = authResponse.UserName
};
return customAuthResponse;
}
// return the standard response
return response;
}
:
{
"sessionId": "bG27SdxbRkqJqU6xv/gvBw==",
"userName": "[email protected]",
"sessionExpires": "2013-04-29T03:27:14.0000000",
"responseStatus": {}
}
私はそうのような認証メソッドをオーバーライドすることができます
セッションが既にアクティブな場合を除いて、これはうまくいきます。その場合には、有効なセッションとautomatically returns a standard AuthResponseためのAuthService Postメソッドをチェックし、それをオーバーライドする明白な方法はありません。
var alreadyAuthenticated = response == null;
response = response ?? new AuthResponse {
UserName = session.UserAuthName,
SessionId = session.Id,
ReferrerUrl = referrerUrl,
};
以下Paaschpaのアイデアに続いて、以下の力再認証は、常に再認証されます
これを行うには、誰かがもっと良い方法を考えることができますか?私は自分のAuthenticationServiceを実装することができますが、私はAuthFeatureをどのようにオーバーライドするのか分かりません。
は、このヘルプのようなものをしていますか? https://github.com/ServiceStack/ServiceStack/wiki/Sessions#using-typed-sessions-in-servicestack – paaschpa
@paaschpa悲しいことではありません。そのカスタムセッション値は、サーバー上に保持されているものです。私はカスタム認証応答を公開したい。何かあればこのようになります:http://stackoverflow.com/questions/13855996/how-to-change-http-401-response-in-servicestackしかし失敗したログインではなく成功したログインのためです。 – Junto