Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for oAuth2 admin page #4451

Merged
merged 5 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/config/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

define('TP_VERSION', '3.1.2');
define("UPGRADE_MIN_DATE", "1727110744");
define('TP_VERSION_MINOR', '147');
define('TP_VERSION_MINOR', '150');
define('TP_TOOL_NAME', 'Teampass');
define('TP_ONE_DAY_SECONDS', 86400);
define('TP_ONE_WEEK_SECONDS', 604800);
Expand Down
8 changes: 4 additions & 4 deletions includes/tables_integrity.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
},
{
"table_name": "background_tasks",
"structure_hash": "edc741f433ca21e21026ad68fab391eecce7c94410c83b6872c748a0188796b6"
"structure_hash": "a16bfe9a8067dbb06f7d7d00192f36602ffa48460ccc5b1d76dbb952f3a0fd12"
},
{
"table_name": "background_tasks_logs",
"structure_hash": "2a49492b97b2dae9f5634a7d7d9eeca80bc61c9b844000fdb368f58711141e0d"
"structure_hash": "e4af7ed71b16cbabb5d8d833d8105fde35fa5fe82cfafc1b45baac6255b33822"
},
{
"table_name": "cache",
Expand Down Expand Up @@ -101,11 +101,11 @@
},
{
"table_name": "log_system",
"structure_hash": "673871da3fc8a6924917691b1a80c79d7fd774a25bc1f63fb8e4872008038b31"
"structure_hash": "27d2764bf1d26a0f483aceaf82075382672563d93ab2a4ae34f0a63a34e801f4"
},
{
"table_name": "misc",
"structure_hash": "0d126563ed82949ee8350ebff92ec382081afda170a778931ac9c2ef8d2c9dc6"
"structure_hash": "aa3b8db6a4d5751b6d006758e152913f82aca172712bc378fb863c6ccc6a4115"
},
{
"table_name": "nested_tree",
Expand Down
3 changes: 1 addition & 2 deletions pages/admin.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ function(data) {
"field": field,
"value": value,
}
console.log(data);

// Store in DB
$.post(
Expand All @@ -231,7 +230,7 @@ function(data) {
);
return false;
}
console.log(data)

if (data.error === false) {
toastr.remove();
toastr.success(
Expand Down
87 changes: 79 additions & 8 deletions pages/oauth.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,90 @@ function(data) {
* On page loaded
*/
$(function() {
// Click on log in button with Azure Entra
$('#oauth2_tenant_id').change(function(event) {
var tenantId = $(this).val();
var endpointUrl = $('#oauth2_client_endpoint').val();
var tokenUrl = $('#oauth2_client_token').val();

// Remplace l'identifiant de locataire dans l'URL du point de terminaison
/**
* Update fields with tenant ID
*
* @param {string} tenantId
*/
function updateFieldsWithTenantId(tenantId) {
// Update field oauth2_client_endpoint
let endpointUrl = $('#oauth2_client_endpoint').val();
endpointUrl = endpointUrl.replace(/([^\/]*)\/oauth2\/v2.0\/authorize/, tenantId + '/oauth2/v2.0/authorize');
$('#oauth2_client_endpoint').val(endpointUrl);

// Remplace l'identifiant de locataire dans l'URL du jeton
// Update field oauth2_client_token
let tokenUrl = $('#oauth2_client_token').val();
tokenUrl = tokenUrl.replace(/([^\/]*)\/oauth2\/v2.0\/token/, tenantId + '/oauth2/v2.0/token');
$('#oauth2_client_token').val(tokenUrl);
}

/**
* Update a setting in DB
*
* @param {string} field
* @param {string} value
* @returns {Promise}
*/
function updateTeampassSetting(field, value)
{
// Check if field and value are not empty
if (field === '' || value === '') {
return false;
}

// Launch the request
return $.Deferred(function(defer) {
$.post(
"sources/admin.queries.php", {
type: "save_option_change",
data: prepareExchangedData(
JSON.stringify({"field": field, "value": value}),
"encode",
"<?php echo $session->get('key'); ?>"
),
key: "<?php echo $session->get('key'); ?>"
},
function(data) {
// Handle server answer
try {
data = prepareExchangedData(data, "decode", "<?php echo $session->get('key'); ?>");
} catch (e) {
// error
defer.reject(e.error);
}

if (data.error === false) {
defer.resolve(data);
} else {
defer.reject(data.error);
}
}
);
}).promise();
}

$('#oauth2_tenant_id').change(function() {
let tenantId = $(this).val();

// Update the fields
updateFieldsWithTenantId(tenantId);

// Update settings in DB
$.when(
updateTeampassSetting('oauth2_client_endpoint', $('#oauth2_client_endpoint').val())
).then(function() {
return updateTeampassSetting('oauth2_client_token', $('#oauth2_client_token').val());
}).fail(function(error) {
toastr.remove();
toastr.error(
'<?php echo $lang->get('server_answer_error') . '<br />' . $lang->get('server_returned_data') . ':<br />'; ?>' + error,
'', {
closeButton: true,
positionClass: 'toast-bottom-right'
}
);
return false;
});
});
});

Expand Down
12 changes: 0 additions & 12 deletions pages/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,6 @@
</div>
</div>

<div class='row mb-2'>
<div class='col-10'>
<?php echo $lang->get('settings_oauth_auto_login'); ?>
<small id='passwordHelpBlock' class='form-text text-muted'>
<?php echo $lang->get('settings_oauth_auto_login_tip'); ?>
</small>
</div>
<div class='col-2'>
<div class='toggle toggle-modern' id='oauth2_auto_login' data-toggle-on='<?php echo isset($SETTINGS['oauth2_auto_login']) === true && (int) $SETTINGS['oauth2_auto_login'] === 1 ? 'true' : 'false'; ?>'></div><input type='hidden' id='oauth2_auto_login_input' value='<?php echo isset($SETTINGS['oauth2_auto_login']) && (int) $SETTINGS['oauth2_auto_login'] === 1 ? 1 : 0; ?>'>
</div>
</div>

nilsteampassnet marked this conversation as resolved.
Show resolved Hide resolved
<div class='row mb-2 tr-ldap'>
<div class='col-5'>
<?php echo $lang->get('app_name'); ?>
Expand Down