IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Question: can I create a server with IdentityServer4 without a UI or using a framework such as Angular 2?

Open rgozim opened this issue 9 years ago • 51 comments

All the samples I've seen for IdentityServer4 use some variation of the QuickStartUI which uses MVC for the UI.

I would like to build my login/logout/etc screens using a framework such as Angular2 and I'm struggling to figure out if it's possible given that every sample in some way uses a redirect to an MVC UI implementation.

Could someone explain to me or show me a sample that is API based and uses a Framework for UI?

rgozim avatar May 18 '17 11:05 rgozim

It's entirely possible, although someone more experienced than I would have to chime in to advise on security of it.

I had a go at it (basically API only IdentityServer and UI hosted elsewhere) a month or so ago, but dropped it because I persuaded us to move in a different direction where having a login page on idsrv was acceptable.

At a very basic level, you'd have to create an API which returned data you needed e.g. external IdP's/Consent for a particular app. Which is simple enough. Inspect what logic the existing controllers do and look at what the views do wrt generating URL's and replicate these on API/your SPA respectively.

As for C/XSRF you can do something like this http://stackoverflow.com/a/44035774/3515174 Not sure what else needs doing for security -- as in, I'm genuinely not sure -- to me this is rather scary -- I would stick with MVC UI... Although I believe it is not intended for production, the QuickStart UI was developed by people who really know this sorta stuff inside out.

ProTip: You can pass idp through acr_values to automatically redirect to external IDP.

Mardoxx avatar May 18 '17 15:05 Mardoxx

The UI is up to you, but the communication between the UI and the IdSvr middleware endpoints is mainly via the authentication cookie that the UI is expected to set. IMO, the UI is much easier to write in server-side rendered code, rather than SPA style.

brockallen avatar May 25 '17 14:05 brockallen

I believe you need to look at the Resource Owner Password flow. Submit your username and pass and receive an access_token, along with a refresh_token. Make sure to set "offline_access" to true in your client config.

danielrjames avatar May 27 '17 07:05 danielrjames

It would be great if you could add a sample of doing this with vanilla javascript. Then everybody could addapt it to their dear framework. The sample could be as simple as possible to just know what are the minimal required things.

RaulRG avatar Jun 01 '17 11:06 RaulRG

You mean like this one? https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/Clients/JavaScriptResourceOwner

brockallen avatar Jun 01 '17 14:06 brockallen

Thank you! I will look at it and see how to adapt it to IdentityServer4.

RaulRG avatar Jun 01 '17 14:06 RaulRG

@rgozim Hi! I'm right with this same drawback of the UI. In some way I manage to solve it, or as it proceeded? I'm thinking about carrying out the password flow and not the implicit one but this openly breaks the OpenID protocol, but the truth is that using Razor and trying to adapt it with Angular or React is being a real headache or very frustrating. If you have any resource to help me do this, I would greatly appreciate it.

ataschz avatar Dec 08 '17 16:12 ataschz

If you don't ask user permission for sending data to the client, then you cannot claim to be using openid connect

TomCJones avatar Dec 08 '17 23:12 TomCJones

@TomCJones Hi, I do not understand your answer, was it for me? What I need to do is change the Razor UI to a UI with Angular or React or any other framework. For now I am experimentally exploring an SPA from .NET and consume the drivers of the QuickStart and modify this logic a little to suit my Angular Front-End application, however I do not know what the result will be.

ataschz avatar Dec 09 '17 22:12 ataschz

Sorry, some how I read your request as asking for an id server with no ui. That would be hard to reconcile with the standard

TomCJones avatar Dec 10 '17 06:12 TomCJones

@TomCJones No. He is not asking for an Id server without UI. He is asking for a UI implemented using just a plain Javascript client and not a MVC ASP.NET one where logic for the UI is delivered by the server. A Javascript client must connect to the ID server just using REST

RaulRG avatar Dec 11 '17 08:12 RaulRG

@RaulRG Thanks for clarifying it. As I was investigating, I can have a SPA directly in an MVC project and make the connection with the .NET drivers to be able to do all the authentication. Now I am experimenting with this, but it is not functioning correctly yet.

ataschz avatar Dec 13 '17 00:12 ataschz

Basic local login should be possible to do. But on top of dealing with cookies, external auth provider middleware (services.AddGoogle etc) works by processing Challenge() into 302 redirect which gets processed by the browser before it gets to XHR API, so it's not possible to get at the redirect URL in JS. May need to look at adding something on the server-side HTTP pipeline to convert redirect to a 200 response with the URL to let JS process it.

ptjhuang avatar Jan 14 '18 13:01 ptjhuang

@brockallen You mentioned that resource owner password grant would be a possible solution. In that case how would you store the client secret and refresh the access token? Is it possible solution to set the ISRV authentication URL to angular route?

feco93 avatar Jan 31 '18 08:01 feco93

@rgozim were you able to use angular 2? did u hit any road blocks if doing so?

vejandla avatar Jul 10 '18 14:07 vejandla

Hi anyone has any opinion now?

lousaibiao avatar Aug 20 '18 08:08 lousaibiao

I'm having the same kind of challenge making a UI using React to deal with all process (login, email confirmation, password reset, new user registration). The lack of guidance in this area is a pity. Would be nice if someone shares some code about this subject...

GersonDias avatar Aug 31 '18 11:08 GersonDias

@gersonDias, i have achieved this by configuring userinteraction options login url. I set the login url to single page application url and from there, you are on your own in writing functionality for the above asked use cases.

I still achieved the antivalidateforgery token functionality, (csrf token/cookie) so that we are not losing anything by going away from MVC to a Spa

One thing i am still looking for a solution is after login to identity provider, if user goes to idp login screen (spa login url), i was not sure how to check whether user logged in or not and if user is logged in i would like to show a basic welcome page.

vejandla avatar Sep 01 '18 23:09 vejandla

I'm having the same kind of challenge making a UI using React to deal with all process (login, email confirmation, password reset, new user registration). The lack of guidance in this area is a pity. Would be nice if someone shares some code about this subject...

I think everyone is having a hard time understanding the relationship between the UI and IdentityServer. The short answer is the authentication cookie. Make your UI do whatever it needs to for any of those things. It's really unrelated to IdentityServer, But when your user wants to authenticate, then you need your server code behind the UI to issue the authentication cookie using the default authentication scheme from in the ASP.NET Core host. That's it. Once that cookie is issued, requests into IdentityServer will then do their job.

brockallen avatar Sep 02 '18 01:09 brockallen

@brockallen Could IdentityServer4 be leveraged for mobile application using a framework such as Flutter? Thanks!

mtkamran avatar Sep 06 '18 21:09 mtkamran