Base solution for your next web application
Open Closed

Determine if user is logged in using token or cookie #1263


User avatar
0
david created

This is probably Identity question, but i would be grateful if you can help.

Basically I would like to know if a user is logged in using token (through API) or using cookies(default login form)

Thanks


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hmmm.. You may directly check if cookie has ASP.NET authentication key. Did you try it? But surely you can not do it in application layer since there is no web code here. If you want to do it in app layer, define an interface and inject into your class and implement it in web layer and register to DI.

  • User Avatar
    0
    david created

    Thanks hikalkan for your suggestion, However i cannot use cookie to determine this info. The reason is that im having two types of users. App users and normal users. Normal users have the UI to create App users. The only difference between them is an enum that defines a user as App user. App users have different set of permissions. No problem on that. Using cookie approach will work in production but will fail in swagger tests because the app user it is used with swagger bearer authentication should probably accessed the ui and generated the cookie on same domain as the swagger(might be wrong here)

    The solution im using now is an app service that determines usertype enum by user id by using usermanager. However i was looking if there was some more elegant and faster already in claims, or maybe provide me some more info regarding your second proposed solution as i haven't got it.

    Thanks again and keep great work.