UNPKG

sessionize-auth

Version:

A flexible session management library for React, Next.js, Angular, and React Native

60 lines (50 loc) 1.48 kB
import { BaseSSOProvider } from "./base"; import { SSOUser } from "../types"; /** * Microsoft OAuth 2.0 Provider */ export class MicrosoftSSOProvider extends BaseSSOProvider { protected getProviderName(): string { return 'Microsoft'; } protected getProviderIcon(): string { return 'https://img.icons8.com/color/48/000000/microsoft.png'; } protected getProviderColor(): string { return '#00BCF2'; } protected getScopes(): string[] { return this.config.scopes || [ 'openid', 'email', 'profile', 'User.Read' ]; } protected getAuthUrl(): string { return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'; } protected getTokenUrl(): string { return 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; } protected getUserInfoUrl(): string { return 'https://graph.microsoft.com/v1.0/me'; } protected parseUserInfo(data: any, accessToken: string): SSOUser { return { id: data.id, email: data.mail || data.userPrincipalName, name: data.displayName, avatar: data.photo ? `https://graph.microsoft.com/v1.0/me/photo/$value` : undefined, provider: 'microsoft', providerId: data.id, accessToken: accessToken }; } protected getCustomParams(): Record<string, string> { return { response_mode: 'query', ...this.config.customParams }; } }