Core: Integrate passportjs with adonis

Created on 30 Nov 2018  路  14Comments  路  Source: adonisjs/core

I am trying to integrate steam login with passportjs.

How can i use passportjs inside adonis? Should i simply do auth.attempt inside passportjs callback?

Most helpful comment

Ok, I have tried this:

const Config = require("@adonisjs/framework/src/Config");

hooks.before.providersRegistered(function() {
  ioc.extend("Adonis/Addons/Ally", "opskins", function() {
    console.log(new Config(`${__dirname}./../config/`));

    return new Opskins(new Config(`${__dirname}./../config/`));
  });
});

It seems to work

All 14 comments

For what purpose are you using Passport js?

@thetutlage I am using pasportjs for authentication through steam login.

I have checked adonis-ally. It looks like passportjs. But It lacks documentation on how to create custom drivers.

What driver you looking for?

@thetutlage The site i am using is not a popular site (opskins.com). So, I am not looking for a ready made driver. I am looking to extend ally to build my own driver. But i am not sure if its possible.

Simply write the following code inside start/hooks.js file under beforeBooted hook.

const { hooks } = require('@adonisjs/ignitor')

hooks.before.providersBooted(function () {
  ioc.extend('Adonis/Addons/Ally', 'opskins', function () {
     return new OpSkins()
  })
})

The OpSkins needs same interface as any of the other drivers. Example: https://github.com/adonisjs/adonis-ally/blob/develop/src/Drivers/Facebook.js

@thetutlage Thanks. I'll give this a try.

Anyway, If i have to authenticate without using ally. How would i do that?
Does simply doing auth.attempt keep track of the auth session?

Yes. I suggest reading the docs thoroughly and also feel free to join our forum or discord server

@thetutlage Thanks.

@thetutlage Just a correction in your code. It should be before.providersRegistered instead of before.providersBooted

@thetutlage I am now getting Cannot read property 'get' of undefined. How can i pass Config to the object like this return new OpSkins(Config) ?

Ok, I have tried this:

const Config = require("@adonisjs/framework/src/Config");

hooks.before.providersRegistered(function() {
  ioc.extend("Adonis/Addons/Ally", "opskins", function() {
    console.log(new Config(`${__dirname}./../config/`));

    return new Opskins(new Config(`${__dirname}./../config/`));
  });
});

It seems to work

@thetutlage i need passport for Oauth2 service and apps even for graphQL user auth, is there any plan to integrate passport or a similar lib?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

umaams picture umaams  路  3Comments

krunaldodiya picture krunaldodiya  路  3Comments

douglaszaltron picture douglaszaltron  路  3Comments

itsg2jakhmola picture itsg2jakhmola  路  3Comments

dezashibi picture dezashibi  路  4Comments