Overview
Icon for Microsoft

Microsoft

Use Microsoft for SSO authentication

Medusa Plugin : Microsoft-SSO

Compatibility

This starter is compatible with versions >= 2.8.3 of Copy to clipboard@medusajs/medusa.

Getting Started

Installation

  1. Run Copy to clipboardyarn add @thepuzzlers/medusa-plugin-microsoft-auth-provider
  2. Add microsoft configuration to the Copy to clipboard.env file
TENANT_ID = "xxxx"
CLIENT_ID = "xxxx"
CLIENT_SECRET = "xxxx"
HOST_URL = "example.medusa.com"

NOTE: the HOST_URL is your medusa url. it's used to create the callback api that back to your medusa application if no callback is provided by the application when requesting the token.

  1. Add the plugin to the providers array of Auth Module in Copy to clipboardmedusa-config.ts
modules: [
{
resolve: "./src/modules/salesRep",
},
{
resolve: "@medusajs/medusa/auth",
dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
options: {
providers: [
// default provider
{
resolve: "@medusajs/medusa/auth-emailpass",
id: "emailpass",
},
{
resolve:
"@thepuzzlers/medusa-plugin-microsoft-auth-provider/providers/microsoft-sso",
id: "microsoft-sso",
options: {
tenantId: process.env.TENANT_ID,

Usage

In mobile app: eg Expo app

import { Button } from "react-native-paper";
import { makeRedirectUri } from "expo-auth-session";
import * as WebBrowser from "expo-web-browser";
import { sdk } from "@/medusa/config";
import * as Crypto from "expo-crypto";
import { getUserDetailFromToken } from "./utils/getUserDetailFromToken";
import { useRouter } from "expo-router";
WebBrowser.maybeCompleteAuthSession();
const redirectTo = makeRedirectUri({
path: "index",
preferLocalhost: true,
});
const getParams = (url: string) => {
const sourceUrl = new URL(url);
const searchParams = new URLSearchParams(sourceUrl.search);
return Object.fromEntries(searchParams.entries());
};

Events

  1. Copy to clipboardmicrosoft_sso.user_authorized : emitted when an user successfully sign in to the app

Sources:

You may also like

Browse all integrations

Build your own

Develop your own custom integraiton

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?