I'm looking to use SSO with web api 2.2 for use in multiple applications, including mobile and asp.net mvc 5.
I got the basic idea of creating authentication token via web api, but i have few questions:
1- Is it safe to store the authentication token in a cookie along with user name?
2- Can I tie that authentication with identity framework in mvc and be able to use roles?
3- How can I validate roles? do I have to send a request to the api for each controller marked as authorized with a certain role to make sure it's the right role for the user?
4- If I log in from web app and get authentication token, and then try to log in from mobile, will it send the same token?
In order to add a Web API Controller you will need to Right Click the Controllers folder in the Solution Explorer and click on Add and then Controller. Now from the Add Scaffold window, choose the Web API 2 Controller – Empty option as shown below. Then give it a suitable name and click OK.
In the management dashboard, click Apps / APIs. Click the application that you want to enable Single Sign On. In the Settings tab, scroll down until you see the Use Auth0 instead of the IdP to do Single Sign On switch. Flip the switch! and save the changes.
Ok so I'll answer this question with what I've done.
The basic architecture will be divided into three main parts:
1- Identity server 4 (using asp.net core).
2- Web api (using asp.net core).
3- Client side (using angular 2), however you can also use any client side framework or asp.net core.
Identity server will generate tokens, which will be sent with each request to the web api, and it does support asp.net identity and roles. This way you can easily extend it for mobile and send the token with each request.
link to identity server 4 docs: http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html
link to github where you can find more examples: https://github.com/IdentityServer/IdentityServer4
android working with identity server 4: https://github.com/leo9223/Android-Resource-Owner-Flow-client-for-IdentityServer4
Note: for asp.net mvc 5, you can use cookie authentication (which will not work for mobile) but will provide SSO for separate applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With