IdentityServer / IdentityServer3

OpenID Connect Provider and OAuth 2.0 Authorization Server Framework for ASP.NET 4.x/Katana
https://identityserver.github.io/Documentation/
Apache License 2.0
2.01k stars 763 forks source link

How to retrieve the login url? #768

Closed imperugo closed 9 years ago

imperugo commented 9 years ago

Hi, my application has different clients and, in my custom owin middleware, I've to check some stuff before go ahead. If something doesn't respect my checks, I've to redirect him to the login page.

How can I get the `core/login?signin=761d9df6ddc9d65e9fa1447b30f772b5? I suppose the signin value is a Guid "cleaned" but probably I've also to create so cookies.

Am I wrong? if not How can I do the redirect correctly?

brockallen commented 9 years ago

Where do you need to get this URL? In your client app? In custom middleware running before IdSvr? Or somewhere in the middle of IdSvr?

imperugo commented 9 years ago

IdSvr is installed on identity.mydomain.com and there are several clients. In this specific case I need to get the url into my custom middleware into a client that is hosted on client5.mydomain.com

brockallen commented 9 years ago

I still don't follow. If you're in a separate app, then you should be making requests to the authorization endpoint in IdSvr, not directly to the login page.

imperugo commented 9 years ago

Let me explain better the scenario. I'm trying to check if the user is authenticated into my custom middewlare. I'm using a middleware because the app is a SPA hosted by OWIN (selfhost) using Microsoft.Owin.FileSystems.

All the files inside are static, so I can't use any AuthorizeAttribute like an MVC/WebAPI application. Basically someone can call the SPA directly into the browser and I need to be sure he has the right roles- Basically I'm trying to do is something like that

public override async Task Invoke(IOwinContext context)
{
    bool isAuthenticated = context.Authentication.User != null && context.Authentication.User.Identity.IsAuthenticated;

    if(!isAuthenticated)
    {
        //Send user to login
        context.Response.Redirect("my login url")
    }

    await Next.Invoke(context);
}

Better?

brockallen commented 9 years ago

Right -- so in essence you're just in a client app and need to get a token. So from here, initiate an authorization request to IdentityServer.

Also, you know, there are ways to do this form the JS as well? Look at the JS client in the sample repo, or the OAuthJS sample.

imperugo commented 9 years ago

Thanks