Disabled local login, and new default oauth instead of choice



  • I have a question regarding the login button in NodeBB. I've currently disabled the local login, and I have created a custom oauth using the sso example plugin. I am planning to only allow this custom SSO solution, but now that i've disabled the local login, it still gives me an option screen to choose logins, instead instantly going for the only option available.

    Can this be fixed by redirecting to my custom sso-auth solution immediately, instead of letting the user choose the only option available?


  • GNU/Linux Admin

    Mm... possibly. In your custom SSO plugin, add a new hook (in plugin.json) to listen for static:app.init, and then add this to library.js:

    OAuth.init = function(data, callback) {
      data.router.get('/login', function(req, res) {
        res.redirect('/auth/myauth');
      });
    };
    

    ... of course, replace myauth with the proper url. YMMV.



  • Awesome, am I correct to assume that this also works for the registration and logout urls?



  • @Mr.-Orange said:

    Awesome, am I correct to assume that this also works for the registration and logout urls?

    That code above only looks for /login, you'd need to add register and logout.



  • That I understood, ;-). But doesn't seem to work, I added the following to hooks object in plugins.json:

    { "hook": "static:app.init", "method": "init"}
    

    And I then proceeded to add your suggested code to the library.js file, but as far as I can tell it doesn't seem to be executed? What am I doing wrong?



  • Can anyone help me?


  • Admin Staff

    @Mr.-Orange The hook is called static:app.load



  • @baris Thanks! I implemented this and it seems to be working. When I go to the address manually (e.g. by typing it in the url bar) the redirect works flawlessly, but when I press the login button on the homepage it keeps redirecting me to the choice screen? What am I doing wrong?


  • Admin Staff

    Post the code you have. You might have to do something like

    data.router.get('/login', function(req, res) {
       if (res.locals.isAPI) {
           res.status(302).json(url);
       }  else {
           res.redirect(url);
       }
    });


  • @baris

    OAuth.init = function(data, callback) {
    	data.router.get('/login', function(req, res) {
            res.redirect('/auth/cws'); 		
    	});
    	callback(null, data);
    };

Log in to reply
 

Suggested Topics

  • 2
  • 6
  • 2
  • 4
  • 4
| |