Skip to content

Commit

Permalink
Also convert JWT Token to JWT Cookie in /session-to-token API
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Dec 7, 2017
1 parent 7f5baac commit 9a6b47c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ServiceStack/Auth/JwtAuthProvider.cs
Expand Up @@ -339,14 +339,18 @@ public object Any(ConvertSessionToToken request)
if (jwtAuthProvider.RequireSecureConnection && !Request.IsSecureConnection)
throw HttpError.Forbidden(ErrorMessages.JwtRequiresSecureConnection);

var session = Request.GetSession();
if (session.FromToken)
return new ConvertSessionToTokenResponse();
if (Request.ResponseContentType.MatchesContentType(MimeTypes.Html))
Request.ResponseContentType = MimeTypes.Json;

var token = jwtAuthProvider.CreateJwtBearerToken(Request, session);
var token = Request.GetJwtToken();
if (string.IsNullOrEmpty(token))
{
var session = Request.GetSession();
token = jwtAuthProvider.CreateJwtBearerToken(Request, session);

if (!request.PreserveSession)
Request.RemoveSession(session.Id);
if (!request.PreserveSession)
Request.RemoveSession(session.Id);
}

return new HttpResult(new ConvertSessionToTokenResponse())
{
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceStack/ServiceStackHost.cs
Expand Up @@ -151,6 +151,8 @@ protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithS
typeof(HotReloadFilesService),
typeof(TemplateApiPagesService),
typeof(TemplateMetadataDebugService),
typeof(ServerEventsSubscribersService),
typeof(ServerEventsUnRegisterService),
};

JsConfig.InitStatics();
Expand Down

0 comments on commit 9a6b47c

Please sign in to comment.