Check application_id before setting redirect URL when using specific Azure endpoints (#1165)

* If using specific AD endpoints, but using the default application ID, the redirect URL does not match. Check if the application_id before setting the redirect URL.
This commit is contained in:
abraunegg 2020-11-26 05:51:29 +11:00 committed by GitHub
parent a4a5a5f267
commit 48fc64a247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,9 @@ private bool simulateNoRefreshTokenFile = false;
private ulong retryAfterValue = 0;
private immutable {
// Client ID / Application ID (abraunegg)
string clientIdDefault = "d50ca740-c83f-4d1b-b616-12c519384f0c";
// Azure Active Directory & Graph Explorer Endpoints
// Global & Defaults
string globalAuthEndpoint = "https://login.microsoftonline.com";
@ -38,8 +41,8 @@ private immutable {
}
private {
// Client ID / Application ID (abraunegg)
string clientId = "d50ca740-c83f-4d1b-b616-12c519384f0c";
// Client ID / Application ID
string clientId = clientIdDefault;
// Default User Agent configuration
string isvTag = "ISV";
@ -138,6 +141,14 @@ final class OneDriveApi
.debugResponse = true;
}
// Update clientId if application_id is set in config file
if (cfg.getValueString("application_id") != "") {
// an application_id is set in config file
log.vdebug("Setting custom application_id to: " , cfg.getValueString("application_id"));
clientId = cfg.getValueString("application_id");
companyName = "custom_application";
}
// Configure tenant id value, if 'azure_tenant_id' is configured,
// otherwise use the "common" multiplexer
string tenantId = "common";
@ -145,7 +156,7 @@ final class OneDriveApi
// Use the value entered by the user
tenantId = cfg.getValueString("azure_tenant_id");
}
// Configure Azure AD endpoints if 'azure_ad_endpoint' is configured
string azureConfigValue = cfg.getValueString("azure_ad_endpoint");
switch(azureConfigValue) {
@ -164,8 +175,16 @@ final class OneDriveApi
log.log("Configuring Azure AD for US Government Endpoints");
// Authentication
authUrl = usl4AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/authorize";
redirectUrl = usl4AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
tokenUrl = usl4AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/token";
if (clientId == clientIdDefault) {
// application_id == default
log.vdebug("USL4 AD Endpoint but default application_id, redirectUrl needs to be aligned to globalAuthEndpoint");
redirectUrl = globalAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
} else {
// custom application_id
redirectUrl = usl4AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
}
// Drive Queries
driveUrl = usl4GraphEndpoint ~ "/v1.0/me/drive";
driveByIdUrl = usl4GraphEndpoint ~ "/v1.0/drives/";
@ -182,8 +201,16 @@ final class OneDriveApi
log.log("Configuring Azure AD for US Government Endpoints (DOD)");
// Authentication
authUrl = usl5AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/authorize";
redirectUrl = usl5AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
tokenUrl = usl5AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/token";
if (clientId == clientIdDefault) {
// application_id == default
log.vdebug("USL5 AD Endpoint but default application_id, redirectUrl needs to be aligned to globalAuthEndpoint");
redirectUrl = globalAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
} else {
// custom application_id
redirectUrl = usl5AuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
}
// Drive Queries
driveUrl = usl5GraphEndpoint ~ "/v1.0/me/drive";
driveByIdUrl = usl5GraphEndpoint ~ "/v1.0/drives/";
@ -200,8 +227,16 @@ final class OneDriveApi
log.log("Configuring Azure AD Germany");
// Authentication
authUrl = deAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/authorize";
redirectUrl = deAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
tokenUrl = deAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/token";
if (clientId == clientIdDefault) {
// application_id == default
log.vdebug("DE AD Endpoint but default application_id, redirectUrl needs to be aligned to globalAuthEndpoint");
redirectUrl = globalAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
} else {
// custom application_id
redirectUrl = deAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
}
// Drive Queries
driveUrl = deGraphEndpoint ~ "/v1.0/me/drive";
driveByIdUrl = deGraphEndpoint ~ "/v1.0/drives/";
@ -218,8 +253,16 @@ final class OneDriveApi
log.log("Configuring AD China operated by 21Vianet");
// Authentication
authUrl = cnAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/authorize";
redirectUrl = cnAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
tokenUrl = cnAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/v2.0/token";
if (clientId == clientIdDefault) {
// application_id == default
log.vdebug("CN AD Endpoint but default application_id, redirectUrl needs to be aligned to globalAuthEndpoint");
redirectUrl = globalAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
} else {
// custom application_id
redirectUrl = cnAuthEndpoint ~ "/" ~ tenantId ~ "/oauth2/nativeclient";
}
// Drive Queries
driveUrl = cnGraphEndpoint ~ "/v1.0/me/drive";
driveByIdUrl = cnGraphEndpoint ~ "/v1.0/drives/";
@ -289,13 +332,6 @@ final class OneDriveApi
bool init()
{
// Update clientId if application_id is set in config file
if (cfg.getValueString("application_id") != "") {
// an application_id is set in config file
clientId = cfg.getValueString("application_id");
companyName = "custom_application";
}
// detail what we are using for applicaion identification
log.vdebug("clientId = ", clientId);
log.vdebug("companyName = ", companyName);