gmail-to-exchange365
Version:
Complete Gmail to Exchange 365 migration tool with UI - Migrate emails, attachments, and folders seamlessly
65 lines • 2.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMSAuthUrl = getMSAuthUrl;
exports.exchangeMSCode = exchangeMSCode;
exports.refreshMSToken = refreshMSToken;
const axios_1 = __importDefault(require("axios"));
const MS_AUTH_URL = "https://login.microsoftonline.com";
const MS_GRAPH_URL = "https://graph.microsoft.com";
function getMSAuthUrl() {
const tenantId = process.env.MS_TENANT_ID || "common";
const clientId = process.env.MS_CLIENT_ID;
const redirectUri = encodeURIComponent(process.env.MS_REDIRECT);
const scopes = [
"https://graph.microsoft.com/Mail.Read",
"https://graph.microsoft.com/Mail.ReadWrite",
"https://graph.microsoft.com/MailboxSettings.ReadWrite",
"offline_access"
].join(" ");
return `${MS_AUTH_URL}/${tenantId}/oauth2/v2.0/authorize?` +
`client_id=${clientId}&` +
`response_type=code&` +
`redirect_uri=${redirectUri}&` +
`response_mode=query&` +
`scope=${encodeURIComponent(scopes)}`;
}
async function exchangeMSCode(code) {
const tenantId = process.env.MS_TENANT_ID || "common";
const clientId = process.env.MS_CLIENT_ID;
const clientSecret = process.env.MS_CLIENT_SECRET;
const redirectUri = process.env.MS_REDIRECT;
const response = await axios_1.default.post(`${MS_AUTH_URL}/${tenantId}/oauth2/v2.0/token`, new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
code: code,
redirect_uri: redirectUri,
grant_type: "authorization_code",
scope: "https://graph.microsoft.com/.default"
}), {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
async function refreshMSToken(refreshToken) {
const tenantId = process.env.MS_TENANT_ID || "common";
const clientId = process.env.MS_CLIENT_ID;
const clientSecret = process.env.MS_CLIENT_SECRET;
const response = await axios_1.default.post(`${MS_AUTH_URL}/${tenantId}/oauth2/v2.0/token`, new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: "refresh_token",
scope: "https://graph.microsoft.com/.default"
}), {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
//# sourceMappingURL=msAuth.js.map