kuzzle

Issue with kuzzle custom strategy


I got a Unable to log in using the strategy "SSO" while building a custom authentication strategy, I used the create hook to create my user when required.

Everything went well including my hook:

    async create(_request: any, credentials: { id: string }, kuid: string) {
      // Create user credential
      const [err] = await to(
        this.ssoRepository.create(
          {
            _id: credentials.id,
            kuid,
          },
          { refresh: "wait_for" },
        ),
      );

      if (err) {
        throw new this.context.errors.InternalError(`Error while creating SSO credentials for user ${kuid}.`);
      }

      return { _id: credentials.id };
    }

Then I consume it using

// If user not exists, we create the user
let createdUser: any;
[err, createdUser] = await to(
  this.kuzzle.query({
    action: "createUser",
    body: {
      content: {
        profileIds: ["default"],
        ...ssoUser,
        courses: [],
        favorites: [],
      },
      credentials: {
        SSO: {
          id: ssoUser!.id,
        },
      },
    },
    controller: "security",
    refresh: "wait_for",
  }),
);

if (err) {
  throw new this.context.errors.InternalError(err.message);
}

return { kuid: createdUser._id };

But I get following error

code: 0 errorName: "Undocumented error" message: "Unable to log in using the strategy "SSO""

Any idea, why I get such issue ?

Regards


Solution

  • I had to use

    return { kuid: createdUser.result._id };
    

    instead of

    return { kuid: createdUser._id };
    

    Because kuzzle is wrapping the created user content