Skip to content

[Bug]: Createing a custom Auth Provider Module for azure (SSO) #10860

Description

@sugumaran-d

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.717.0",
    "@aws-sdk/lib-storage": "^3.721.0",
    "@azure/msal-node": "^2.16.2",
    "@medusajs/admin-sdk": "2.1.1",
    "@medusajs/cli": "2.1.1",
    "@medusajs/framework": "2.1.1",
    "@medusajs/js-sdk": "^2.1.3",
    "@medusajs/medusa": "^2.1.3",
    "@medusajs/medusa-js": "^6.1.9",
    "@medusajs/types": "^2.1.3",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@types/multer": "^1.4.12",
    "archiver": "^7.0.1",
    "awilix": "^8.0.1",
    "axios": "^1.7.9",
    "express-session": "^1.18.1",
    "jsonwebtoken": "^9.0.2",
    "medusa-plugin-auth": "^1.11.1",
    "multer": "^1.4.5-lts.1",
    "passport": "^0.7.0",
    "passport-azure-ad": "^4.3.5",
    "passport-google-oauth20": "^2.0.0",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.1.1",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/express-session": "^1.18.1",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/passport": "^1.0.17",
    "@types/passport-azure-ad": "^4.3.6",
    "@types/passport-google-oauth20": "^2.0.16",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "peerDependencies": {
    "@medusajs/medusa": "2.1.1"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v22.11.0

Database and its version

16.2

Operating system name and version

windows

Browser name

No response

What happended?

I have added the custom AUTH for Azure. I have added an identifier as azure

class AzureAuthProviderService extends AbstractAuthModuleProvider {
static identifier = "azure"; // Correct provider identifier
protected logger_: Logger;
protected options_: Options;
protected passport;

this is my config

{
resolve: "@medusajs/medusa/auth", // Medusa's authentication module
options: {
providers: [
{
resolve: "./src/modules/azure", // Path to your custom Azure auth provider
id: "azure",
options: {
clientId: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET,
tenantId: process.env.AZURE_TENANT_ID,

          callbackUrl: 'http://localhost:9000/auth/customer/azure/callback',
        },
      },}

Expected behavior

provided url to login with azure (microsoft)

Actual behavior

getting error

{
"type": "unauthorized",
"message": "\n Unable to retrieve the auth provider with id: azure\n Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.\n "
}

Link to reproduction repo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions