JWT Auth API

JSON Web Token Authentication for your OctoberCMS API integrated with RainLab.User

Back to JWT Auth API Support

chris10207
chris10207

Hi, I am wondering if we can do the following:

  • I have one website with a login form on a server
  • I have 2 webapps running on 2 different servers
  • from the website login page, I would like to login (using the JWT Auth Api) to one of the 2 webapps, then redirect to this webapp and access my dashboard and features.

Is this possible with this plugin? Thanks for your assistance

vdomah
vdomah

I think you can if i understand you right. The goal in your case is to obtain the token from webapp API, wich will be created by plugin. Then using that token you can manipulate what you need, storing in session or sending somewhere depending on your needs.

If you talking about backend dashboard - plugin won't help you because it works only with frontend user system. But u can adjust it's code if needed

chris10207
chris10207

thanks for your reply basically, i am trying to login my users from another website. yes only frontend

so what i did is:

  • with postman, login to the JWT Api, and get token it works fine
  • from the browser navigate to the url of my webapp adding ?token={token}
  • and try to get that token back somehow but i cant see to get it or where. THe idea is to get the token and then authenticate a user.
  • also I try to use the alias JWAuth from my webapp plugin but the class is not resolved, i wonder why.
chris10207
chris10207

alright, I think I made work like this

in my webapp, i created a routes.php with the following code


App::before(function ($request) {

    if (App::runningInBackend()) {
        return;
    }

    if (null == Auth::getUSer()
        && $token = Request::get('token')) {

        $user = JWTAuth::parseToken()->authenticate();
        Auth::login($user);

    }

});

Last updated

1-4 of 4