c# - Automatically login local user after registration with IdentityServer3 -
using identityserver3 need automatically login , redirect local user client application after user has completed registration process. there elegant way this? digging suspect not, in case there hack can use achieve this?
i able achieve external users using custom user service, utilized partial login. however, local users aren't in authentication process handled user service until login username , password.
please note don't have access users password registration process covered multiple screens / views in instance required verify email part of registration process.
progress:
i've found https://github.com/identityserver/identityserver3/issues/563 haven't worked out how trigger redirect.
i'm attempting issue authentication token using:
var localauthresult = userservice.authenticatelocalasync(user); request.getowincontext().authentication.signin(new claimsidentity(localauthresult.result.user.claims, thinktecture.identityserver.core.constants.primaryauthenticationtype));
but best can far redirect user login screen:
httpcookie cookie = request.cookies["signin"]; // stored @ beginning of registration process return redirect("~/core/login?signin=" + cookie.value);
add registration link login page using loginpagelinks:
var authoptions = new thinktecture.identityserver.core.configuration.authenticationoptions { identityproviders = configureidentityproviders, enablelocallogin = true, enablepostsignoutautoredirect = true, loginpagelinks = new loginpagelink[] { new loginpagelink{ text = "register", href = "register" } } };
using loginpagelinks result in signin url parameter added end of url on login page. needs preserved if registration process spans multiple pages. easy store value in cookie.
a gotcha registration page must exist under same url identity server, e.g. "core". allow pages share cookies identity server. in standard mvc controllers can achieved using route decorator:
[route("core/register")] [httpget] [allowanonymous] public actionresult register(string signin) { response.cookies.add(new httpcookie("signin", signin)); // preserve signin can use automatically redirect user after registration process return view(new registerviewmodel()); }
once registration process has been completed can use issuelogincookie extension method create login cookie. signin url parameter can used getsigninmessage extension method retrive returnurl redirect response automatically login user , return them client application:
using thinktecture.identityserver.core.extensions; using thinktecture.identityserver.core.models; ... authenticatedlogin login = new authenticatedlogin() { identityprovider = thinktecture.identityserver.core.constants.builtinidentityprovider, subject = userid, name = authobjects.authuserservice.getdisplaynameforaccount(userid) }; request.getowincontext().environment.issuelogincookie(login); httpcookie cookie = request.cookies["signin"]; if (cookie != null) { signinmessage message = request.getowincontext().environment.getsigninmessage(cookie.value); return redirect(message.returnurl); } else ...
Comments
Post a Comment