Web api bearer token example
Вставка
- Опубліковано 6 лют 2025
- In this video we will discuss how to use bearer token for authentication and retrieving data from the server.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our UA-cam channel. Hope you can help.
/ @aarvikitchen5572
We want to implement a page that retrieves employee data from the server. If the user is not authenticated, he should be automatically redirected to the login page. The user should be able to get to the data page, only if he is logged in.
At the moment, the only way to log off the user is by closing the browser window. As we are storing the bearer token in browser session storage, when we close the browser we loose it from the session. In our next video we will discuss, how to explicitly log out the user without closing the browser window.
Text version of the video
csharp-video-tu...
Slides
csharp-video-tu...
All ASP .NET Web API Text Articles and Slides
csharp-video-tu...
All ASP .NET Web API Videos
• ASP.NET Web API tutori...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
Thank you! Thank you! Thank you!
Your videos are a massive help for my university project. With your guidance I was able to get everything working
Greetings from Germany
kudvenkat dear my brother you are the best. greeting from turkey
Nice lessons provided by you in different concepts, keep going and help us as usual, Big Thank you!
Superb video with succinct explanation.
THANK YOU PRAGIM,
You are doing your best and helping i mean Teaching Many of us, how to programming.
In my Language i say: MUITO OBRIGADO
Yeah..Yo videos is great sir..4 moving 4ward..in d career life. .
Bt,
Nt looking d clearly videos in Android mobile sir.
Great video. Thank you.l
I like your tutorials very much, nice job
11:47 I thought it should be tblBody and not tblData. But I found that both of them will put the rows inside tbody. jQuery magic!
Hi, great video as always. Please continue with web api. Can you make a video using JWT (JSON web token) between client and server. Thanks!
please sir i need refresh token demo thanks you are more helpful
it was excellent
NIce Video.. Can we you please make a video of bearer token with .NET CORE
Plzz make C C++ Programming Tutorials You're tutorial so nice easy to understand....
thanks alot my pro
Hello, My understanding on Web API is that its stateless http protocol. But here we do use sessionStorage to use / identify sessions. Is it violating RESTFUL service principles ? Can you please clarify ? If my question is irrelevant please ignore.
Thank you for the video but in last you forgot to tell to remove authorized from controller. I was getting unauthorized error..
You should not remove authorized. If you are getting 401 error make sure that you have space after to Bearer (inside the string)
The word "thank you" is very little compared to what you offer to all of us.
Can anyone please tell in which table is stored the Bearer token in the server side, and is able to authenticate the client ?
Thank you very much in advance.
How the token value is differentiated from user, can 2 user from 2 different machine pass the same token in the Authorization header for calling 1 api?
I have been running this example with visual studio 2015 community edition but token request has been working fine with Fiddler and when using access_token with other request like employee Get method it has been working with Fiddler but when calling as per given example it shows error. Can someone help me out in resolving this issue.
The gender pay gap is real at kudvenkat industries
Why does that bother everyone so much? The pay gap may be due to the positions and experience they hold.
how server validates user token for particular user for 2nd request ...where token will be saved in server..?
Token wont be saved at server side but did you able to figure it out how Token is getting validated at server side on second request ?
@@ksksai if client is sending token how server will come to know its same client
there has to be validation right...
by the way am UI dev ...so not much into server side
let me know if you know ...
Thanks Dude. :)
it is headers not header that might be your mistake :)
Hello, can you please tell us how to upload multiple file using web api.
have you find the answer? please share with us.
gr8
Hello Sir,
Actually I have written the same code but still i am getting error message on data.html page i also tried to access this page after login but again facing same issue even i checked the value of access Token it was same
Please help me to resolve this issue
Respected Sir, it working fine but how to send token when requesting from MVC Controller to API Controller ? Without Using Ajax
Is this code same for asp.net core?
THANKS THANKS THANKS
Sir please tell me how to decorate the EmployeeContrioler GET method for this video which you retrive data from the controler username and password ( part 25 )
can u provide the whole code, it is little bit confusing?
Hi,
How do refresh my token on every request.
For Instance.
In my API i have set expired token as 5 mins for an example, even though I'm using my web page continuously without being idle my token will be expired after 5 mins.
How do we resolve this, meaning how do i refresh token on every request or is there any way to handle this?
Hi, I made a separate location for the JS file and then added location in BundleConfig.cs. Now, If I reload data.html page and set a breakpoint at " if (sessionStorage.getItem('accessToken') == null) { window.location.href = "Login.html"; }", the step passes this condition for infinity times and as a result login page also refreshes infinity times. Could you please let me know the reason?
i got same issue how did you resolve it.
I am facing a problem which is not related to this topic. Actually, I was trying to host this Web API service on the IIS. I can access Login.html, Registration.html, Data.html pages from debugging mode. But after adding this service (publish) on the IIS I could not access those pages, it appears as a blank page. In browser console it's showing me this error message "Unchecked runtime.lastError: Could not establish the connection. Receiving end does not exist.". Does anyone know this issue or what I am doing wrong here? Thanks in advance.
how to generate "Refresh token" and "Access Token" ?
Thank you sir
Hi all, Please anyone let me know how the Token is getting validated at server side when we click on Load Employee button ?
I logged in with the credentials and when I clicked on LoadEmployees button why it says {"Message":"Authorization has been denied for this request."}
var token = sessionStorage.getItem('accessToken');
var headers = {};
if (token) {
headers.Authorization = 'Bearer ' + token;
}
$('#btnLoadHospital').click(function () {
$.ajax({
url: '/api/HospitalUser',
method: 'GET',
headers: headers,
success: function (data) {
you should consider in Authorization Header 'Bearer ',you should keep a space 'Bearer ' not 'Bearer'
@@subhashpandey6035 VERY helpful, thank you so much.
Hello..sir,
Yo videos r nt displaying clearly.
when i logged in i click on load employees and modal popups your session expired please login again ...and it came back to login page ...i have properly check timespan.fromseconds(10)...but dont know why it is happening... Please Help me...anyone....
I have the same error, did you solve it ?
No ....i have finally left this...and move to next video series....may be you may help me...please let me know if you finally done this...thnx in advance
Sorry ! Not Yet
I have same error wasted 2-3 hours couldnt find solution :-(
let me know if you find the solution
Hi again,
when I used localStorage instead of sessionStorage it worked