IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Auto login after registration

Open Sn3b opened this issue 10 years ago • 8 comments

Is it possible with Identity Server 4 to have auto login after registration of a new user (for a SPA)?

Sn3b avatar Mar 04 '16 12:03 Sn3b

We will support that, but everything around that is still a work in progress.

brockallen avatar Mar 04 '16 13:03 brockallen

aaaaaaaaah good to know ;)

Thanks!

Sn3b avatar Mar 04 '16 13:03 Sn3b

Just know that you will probably skip any email verification in the process of doing that. It really depends on your setup, but you can implement a UserService on identityserver to register users for you. I'm not sure if its present in the current samples, but you could built it yourself. Second option have identityserver just authorize and issue tokens, and your api do the actual user registration with a Resource Owner type setup.

So you could potentially do this (if you have a resource owner setup):

  1. In your register() function on the SPA do a POST /api/register which returns userId/true if successful. Your api/register function will have [AllowAnonymous] attribute (or no [Authorize] attribute. Just make sure your API is closed off with CORS.
  2. Then in same call, request token from IdentityServer with username and password used in previous step: /connect/token (You will need some UserService setup on your IdentityServer, theres an example on one of the questions in this repo). IdentityServer issues token save that in your SPA (cookies, local/session storage).
  3. Log the user into your SPA by checking if the token is valid or get user info. Use the token with headers Authentication: Bearer <token> and call the API as you wish.

Maybe the identityserver security masters can comment on this if there are any big security flaws in my design, as I would like to know as well :)

And also how to fix the security holes of course!!!

I hope this helps.

nikoszs avatar Mar 04 '16 14:03 nikoszs

I thought UserService was gone in version 4?

Sn3b avatar Mar 04 '16 14:03 Sn3b

everything around that is still a work in progress

:)

brockallen avatar Mar 04 '16 14:03 brockallen

Ah that too ;)

Ok I'll wait :D

Sn3b avatar Mar 04 '16 14:03 Sn3b

Hi guys, i see this issue is now closed. is there per-chance a sample on how to implement this. Thanks :)

primalfear avatar Jul 13 '16 10:07 primalfear

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 15 '20 18:01 lock[bot]