Return DisplayName correctly and Meta


Do I need to do anything special to return the DisplayName back?

and I know that I’ve asked this but did not got a full answer…

how can I pass some meta values back, what method should I override and how should I append to what object so this return object can have some custom information like the userGuid or LastLoginDate

why do not create a new service to return the UserAuth information?
I think /Authentication is to authenticate user, i do not know if it can be used by “get”.

The UserSession needs to have DisplayName populated otherwise it falls back to UserName.

You can populate the AuthenticateResponse DTO with a Meta Dictionary of values inside a Response filter (i.e. check if dto is AuthenticateResponse) or if you’re using a Custom AuthProvider you can override Authenticate() and populate AuthenticateResponse Meta Dictionary there.

Great tips @mythz

I ended up using:

public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
    var authenticate = base.Authenticate(authService, session, request) as AuthenticateResponse;
    var authSession = authService.GetSession() as MyCustomAuthSession;

    if (authenticate != null && 
        authSession != null && 
        authSession.CurrentCompany != null && 
        authSession.CurrentUser != null)
        var meta = new Dictionary<string, string>
            {"UserId", authSession.CurrentUser.Guid.ToString("D")},
            {"CompanyId", authSession.CurrentCompany.Guid.ToString("D")}

        authenticate.DisplayName = authSession.CurrentUser.DisplayName ?? authSession.CurrentUser.Email;
        authenticate.UserId = meta["UserId"];
        authenticate.Meta = meta;
    return authenticate;

and the /auth response is now:

  "userId": "741d466b-4334-46fc-ac89-a2e2a0bc488a",
  "sessionId": "Y5UFipNkkaUU2Bol3WED",
  "userName": "",
  "displayName": "Bruno Alexandre",
  "referrerUrl": null,
  "responseStatus": {
    "errorCode": null,
    "message": null,
    "stackTrace": null,
    "errors": null
  "meta": {
    "UserId": "741d466b-4334-46fc-ac89-a2e2a0bc488a",
    "CompanyId": "85ad91fb-c4cb-461d-a5fb-89981414aa70"

Thank you!

1 Like