Oauth token using multiple applications

My application structure is similar to below -

https://democompany.com/ https://democompany.com/app1 https://democompany.com/api 

The user logs in to the main website url https://democompany.com/logon.aspx , which is an asp.net web form application.

App1 is an angularjs app that uses the / api app. api is a webapi2 application that uses oauth authentication for authentication. I would like the user login once on democompany.com/logon.aspx and pass the oauth token to the angularjs application.

Is there a recommended way to pass the oauth token from one application to another.

+5
source share
2 answers

As long as your applications use one subdomain, you can use window.localStorage on the client side for these purposes.

 // to set token in storage window.localStorage.setItem('access_token', access_token); // to get token from storage access_token = window.localStorage.getItem('access_token'); 

This way, you will have access to this repository from every page with some javascript code. For example, with the combination of angular + web.api, you can configure the token for all your requests in the $ http service:

 $http.defaults.headers.common['Authorization'] = "Bearer " + token; 

You can also use an interceptor to set the token if you want more control over your code.

+4
source

I believe that what you describe is the definition of cookies.

0
source

Source: https://habr.com/ru/post/1235747/


All Articles