asp.net web api - OWIN Authentication Server for multiple applications -
i in process of implementing solution has mvc client (lets call client @ localhost:4077/) webapi service (called api @ localhost:4078/)
i have implemented owin oauth in api wanted know whether owin implemented in separate solution (lets call auth @ localhost:4079/token) generate token client, client passes api (as bearer authorisation token)
the reason querying there additional webapi services accessed client , i'd use owin between client , api services.
the issue not sure if token generated auth service used authorise requests on client , api services.
has implemented , if provide example, pretty new owin , oauth appreciated
separating authorization server resource server extremely easy: work without code if use iis , if have configured identical machine keys on both applications/servers.
supporting multiple resource servers bit harder implement owin oauth2 server if need select endpoints access token can gain access to. if don't care that, configure resource servers same machine keys, , you'll able access apis same tokens.
to have more control on endpoints can used access token, should take @ aspnet.security.openidconnect.server
- fork of oauth2 server comes owin/katana - natively supports scenario: https://github.com/aspnet-contrib/aspnet.security.openidconnect.server.
it's relatively easy set up:
add new middleware issuing tokens in authorization server application (in startup.cs
):
app.useopenidconnectserver(new openidconnectserveroptions { provider = new authorizationprovider() });
add new middleware validating access tokens in different api servers (in startup.cs
):
app.usejwtbearerauthentication(new jwtbearerauthenticationoptions { // allowedaudiences must contain absolute url of api. allowedaudiences = new[] { "http://localhost:11111/" }, // x509certificatesecuritytokenprovider must initialized issuer corresponding absolute url of authorization server. issuersecuritytokenproviders = new[] { new x509certificatesecuritytokenprovider("http://localhost:50000/", certificate) } }); app.usejwtbearerauthentication(new jwtbearerauthenticationoptions { // allowedaudiences must contain absolute url of api. allowedaudiences = new[] { "http://localhost:22222/" }, // x509certificatesecuritytokenprovider must initialized issuer corresponding absolute url of authorization server. issuersecuritytokenproviders = new[] { new x509certificatesecuritytokenprovider("http://localhost:50000/", certificate) } });
finally, add new openid connect client middleware in client app (in startup.cs
):
app.useopenidconnectauthentication(new openidconnectauthenticationoptions { // essential parameters have been omitted brevity. // see https://github.com/aspnet-contrib/aspnet.security.openidconnect.server/blob/dev/samples/mvc/mvc.client/startup.cs more information // authority must correspond absolute url of authorization server. authority = "http://localhost:50000/", // resource represents different endpoints // access token should issued (values must space-delimited). // in case, access token requested both apis. resource = "http://localhost:11111/ http://localhost:22222/", });
you can have @ sample more information: https://github.com/aspnet-contrib/aspnet.security.openidconnect.server/blob/dev/samples/mvc/
it doesn't use multiple resource servers, shouldn't hard adapt using different steps mentioned. feel free ping me if need help.
Comments
Post a Comment