Authentication / Authorization

The Beapi Springboot Starter has several built-in tools to help you get loggedIn/Logout and secure your users access.. Below is an explanation of those tools and how to use them.


Authentication/Authorization

User management including authentication/authorization are BUILT-IN. You can login and get a token using the following methids...

  • Authentication
    Assuming you already have a 'registered acct', you can 'authenticate' using the following command:

    curl -v -c ./cookies.txt -H "Content-Type: application/json" -X POST -d '{"username":"YOUR_USERNAME","password":"YOUR_PASSWORD"}' http://YOURSITE:8080/authenticate

    An example of authenticating via Javascript/Jquery is below:



  • Authorization
    Once you get back a token, you can use it in followup requests like so:

    curl -v -b ./cookies.txt -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_TOKEN" --request GET "http://YOURSITE:8080/v1.0/user/show?id%3Dtest"

Refresh Token

Tokens expire every 24 hrs so to keep from having to send your credentials again, you use the '/refreshToken' endpoint. When calling the endpoint, you have to send your existing token and your username:

curl -v -b ./cookies.txt -H "Content-Type: application/json" -H "Authorization: Bearer eyJvcmlnaW4iOiIxMjcuMC4wLjEiLCJicm93c2VyIjoiVW5rbm93biIsIm9zIjoiVW5rbm93biIsImFsZyI6IkhTNTEyIn0.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTczODQ0NDcyMywiaWF0IjoxNzM4MzU4MzIzfQ" --request GET "http://localhost:8080/refreshToken?name=admin"