Adding authentication provider results in "Unknown provider."

sorry. please help me.
I want to add “LINE” to the authentication providers.

Based on this article, I built it as follows.

Developed with reference to the following article. but I get the following error:

{
  "data": null,
  "error": {
    "status": 400,
    "name": "ApplicationError",
    "message": "Unknown provider.",
    "details": {}
  }
}

I have successfully authenticated and successfully obtained an AccessToken.
What should I do to get rid of this error?
Thank you

Below is the code I developed.

I temporarily registered it in provider-registry as follows.

async line({ accessToken }) {
    console.log("accessToken", accessToken);
    const line = purest({ provider: "line" });
    const me = await line.get("me").auth(accessToken).request();
    // test data
    return {
      username: "test",
      email: "test@strapi.io",
    };
  },

I registered the information in bootstrapi as follows

const grantConfig = {
    ...getGrantConfig(baseURL),
    line: {
      enabled: true,
      state: true,
      nonce: true,
      oauth: 2,
      icon: "line",
      key: process.env.LINE_OAUTH_KEY,
      secret: process.env.LINE_OAUTH_SECRET,
      callback: `${baseURL}/line/callback`,
      scope: ["openid", "identify"],
    },
  };

I also referenced this topic. Thanks to this article, most of the errors have been resolved.

@yuichiromukaiyama Do you add Line config to users-permissions/server/bootstrap/grant-config.js

thank you for making sure!
I have added below location.

Perhaps I’m writing in the wrong place…?
(Do I have to change directly in node_modules…?

src/extensions/users-permissions/server/bootstrap/index.js

Do you execute some initial steps in bootstrap? I think users-permissions need save all providers into database. In default users-permissions plugin’s bootstrap/index.js, you can see these codes.

module.exports = async ({ strapi }) => {
  const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });

  await initGrant(pluginStore);
  await initEmails(pluginStore);
  await initAdvancedOptions(pluginStore);

  await strapi.admin.services.permission.actionProvider.registerMany(
    usersPermissionsActions.actions
  );

  await getService('users-permissions').initialize();
  ......
1 Like

I think this plugin method maybe not work because of offical ‘users-permissions’ plugin will overwrite your custom version.

Thank you.
I was using a copy from bootstrap/index.js. Therefore, the initialization step was stepped on.

I guess I’ll do fork…

New findings.

Adding the following line to src/extensions/users-permissions/strapi-server.js changed the error

“Unknown provider.” → “404 Not Found”

"use strict";
module.exports = (plugin) => {
  console.log("strapi-server.js", plugin.services);
  plugin.bootstrap = require("./server/bootstrap");
  plugin.services["providers"] = require("./server/services/providers");
  plugin.services["providers-registry"] = require("./server/services/providers-registry"); // new 
  return plugin;
};

After much trial and error, we succeeded!
The following points were the main points of modification

Modify src/extensions/users-permissions/strapi-server.js as follows

"use strict";
module.exports = (plugin) => {
  console.log("strapi-server.js", plugin.services.toString());
  plugin.bootstrap = require("./server/bootstrap");
  plugin.services["providers"] = require("./server/services/providers");
  plugin.services["providers-registry"] = require("./server/services/providers-registry");
  return plugin;
};

src/extensions/users-permissions/server/bootstrap/index.js

const grantConfig = {
    ...getGrantConfig(baseURL),
    line: {
      enabled: true,
      state: true,
      nonce: true,
      oauth: 2,
      icon: "line",
      key: process.env.LINE_OAUTH_KEY,
      secret: process.env.LINE_OAUTH_SECRET,
      callback: `${baseURL}/line/callback`,
      scope: ["openid", "profile", "identify"],
    },
  };

src/extensions/users-permissions/server/services/providers-registry.js

async line({ accessToken }) {
    const line = purest({ provider: "line" });
    const me = await line.get("profile").auth(accessToken).request();
    return {
      username: me.body.displayName,
      email: `${me.body.userId}@strapi.io`,
    };
  },

I think I succeeded in overwriting it by porting providers-registry.js and reloading it again.
I checked Strapi’s Admin Panel and confirmed that the user account has been added.

The rest… Now if only I could figure out how to redirect to the front end after successfully adding an account… perfect!
(under investigation)

I was able to add callback processing and complete the development.
Thank you for your help!

complete version