Nathiel Barros
Nathiel Barros

Reputation: 715

How to get bearer token to a aspnet razor page

I have a question about Bearer Token on asp.net WebApi. I've been creating WebApi's but just to be consumed by some client(Android,iOS), but now I need to create a Login page in this same project and I don't know how to handle this, since once using a client app, i just make a request to api/token and get the access token, but how to get this from a Web Page? Do I need to use some back-end like NodeJs or AngularJS ?

This is the endpoint :

app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions()
        {
            TokenEndpointPath = new PathString("/Token"),
            Provider = new ApplicationOAuthProvider(),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(300),
            AllowInsecureHttp = true
        });

Upvotes: 1

Views: 2711

Answers (1)

Jamadan
Jamadan

Reputation: 2313

Essentially, whatever you use on the client side to get the token (I use Angular and React as they have in built functionality for making http requests), you then need to get the response and store the token in the client. Take a read of this https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage. It should give you a bit of insight into client side storage. Again I tend to use cookies as it's built in with a lot of the .net MVC stuff, but you could use session storage also

Upvotes: 1

Related Questions