Overview
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
- Run Copy to clipboard
yarn add @thepuzzlers/medusa-plugin-microsoft-auth-provider
- Add microsoft configuration to the Copy to clipboard
.env
file
1234TENANT_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.
- Add the plugin to the providers array of Auth Module in Copy to clipboard
medusa-config.ts
1234567891011121314151617181920modules: [{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
1234567891011121314151617181920import { 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
- Copy to clipboard
microsoft_sso.user_authorized
: emitted when an user successfully sign in to the app
Sources:
- Medusa Plugins documentation
- Create Auth Provider Plugin
- Medusa installation
- Medusa auth google provider plugin
- Microsoft OIDC
- Request an authorization code
- PKCE auth flow with rfc
- Medusa Third party service auth flow
- Medusa Third party social login storefront
- The Medusa auth plugin, using the deprecated version of passport-azure-ad
- Microsoft id_token properties
- Example of decoded id_token after the access_token redemption
- Custom auth strategy
- React Native Authorization Code Grant Flow
- adding changeset