import { type AuthProviderMaterializedConfig } from '@convex-dev/auth/server';

export const Entra: AuthProviderMaterializedConfig = {
  id: 'microsoft-entra-id',
  name: 'Microsoft Entra ID',
  type: 'oauth',
  issuer: process.env.AUTH_MICROSOFT_ENTRA_ID_ISSUER!,
  client: {
    id: process.env.AUTH_MICROSOFT_ENTRA_ID_ID!,
    secret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET!,
  },
  authorization: {
    url: process.env.AUTH_MICROSOFT_ENTRA_ID_AUTH_URL!,
    params: {
      scope: 'openid profile email offline_access',
      response_type: 'code',
    },
  },
  token:
    'https://login.microsoftonline.com/16200986-86f1-44d2-974c-cfa99352722c/oauth2/v2.0/token',
  userinfo: 'https://graph.microsoft.com/oidc/userinfo',
  allowDangerousEmailAccountLinking: true,
  profile(profile) {
    return {
      id: profile.sub,
      name: profile.name,
      email: profile.email,
      //image: profile.picture,
    };
  },
};
