IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Login to web app from a third party POST request, does such a flow exist?

Open naeemsarfraz opened this issue 9 years ago • 12 comments

I'd appreciate any guidance on the following scenario.

App A (web application) uses the hybrid flow to secure access to it and get access to various APIs. The app and APIs are MVC 4.5 and are now using Identity Server 4 which works as expected.

From within a third party app users would like to view a subset of data from App A and they do this by clicking a link (2 - see image below) which posts an XML payload to an end point I control and result in the user being logged into App A and redirected to a specific page. The payload describes the user so we can identify him\her and have been authenticated by the third party app but not against our auth server. The user shouldn't see a login form as it is assumed the payload describes an authenticated user.

My plans were to create App B (web api) which receives this payload (3) and then triggers one of the auth flows (4, 5) to log the user into App A (6, 7). The question is, is there a flow for this type of interaction? Or am I looking at setting the auth cookie for App A manually but use client credentials or resource owner flow to get an access token in the background so that we can call other APIs from App A.

third party login

The third party app does not require access to our APIs, it just wants to hand off the user to us and expect we log them in automatically.

naeemsarfraz avatar Apr 03 '17 12:04 naeemsarfraz

@naeemsarfraz if i understand your scenario correctly, would it be better for the third party app to get an access_token from the identityserver rather than handing off the XML payload to your WebApi to do the authentication for you? Since your WebApp A only trust IdentityServer4 as the authentication/identity provider.

In identityserver you could create a new client and assign a scope that has limited access to your WebAPI or WebApp A resources (i.e. scope.readonly).

kenneth-y avatar Apr 03 '17 15:04 kenneth-y

Does that XML also contain a password? Or how is this trusted?

leastprivilege avatar Apr 03 '17 15:04 leastprivilege

@leastprivilege there is no password however the XML contains a "token" which we validate against a http endpoint, if the endpoint says the token is valid we can assume it's good to proceed.

naeemsarfraz avatar Apr 03 '17 15:04 naeemsarfraz

OK - well then you can sigin the user into the app, right?

leastprivilege avatar Apr 03 '17 15:04 leastprivilege

@kenneth-y yes that would be better but that's a much bigger piece of work for a team upstream. It's not going to be possible right now.

@leastprivilege You know that saying everything looks like a nail when you have a hammer?

I was looking for a way to get Identity Server involved in this dance but your question has got me thinking. If I've validated the token then I could skip steps 4 & 5, go straight to 6, and sign the user in by setting the auth cookie.

Once signed in to App A I will need an access token (to get to APIs) & identity token (for the standard set of claims). I'm not sure how I can get these which is why I was looking at getting my Identity Server involved. I have access to the secret used by App A for hybrid flow. I thought I needed an authorization code to get the access token from here?

var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, "appa.client", "secret"); var tokenResponse = await tokenClient.RequestAuthorizationCodeAsync(??????, "{redirecturi}");

naeemsarfraz avatar Apr 03 '17 21:04 naeemsarfraz

Well - you can get IS involved - implement an extension grant - sent you XML doc to the token endpoint, validate it, return an access token.

leastprivilege avatar Apr 04 '17 06:04 leastprivilege

All set on this issue -- can we close?

brockallen avatar Apr 09 '17 19:04 brockallen

I'm nearly there. I've got my extension grant up and running. Appreciate how well designed IS is so you can plug these things in really easily.

Any advice on how I would go about getting an Identity Token after I've got my access token using the external grant?

naeemsarfraz avatar Apr 10 '17 13:04 naeemsarfraz

You can't get an identity token this way - but an access token that you can send to the userinfo endpoint.

leastprivilege avatar Apr 10 '17 13:04 leastprivilege

Any update on the issue? closing for now - feel free to re-open if it needs further discussion.

leastprivilege avatar Apr 11 '17 06:04 leastprivilege

Thanks for your help, I think I've got what I needed.

naeemsarfraz avatar Apr 11 '17 07:04 naeemsarfraz

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 14 '20 20:01 lock[bot]