Skip to content

Commit

Permalink
Implemented redirect_uri field
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablofl01 committed Sep 1, 2024
1 parent f2219d0 commit 2798ac3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- name: Create artifact
uses: montudor/[email protected]
with:
args: zip -X -r build/wp-openid.zip . -x *.git* node_modules/\* .* "*/\.*" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md *.dist composer.* dev-helpers** build**
args: zip -X -r build/wp-openid-siu-upm.zip . -x *.git* node_modules/\* .* "*/\.*" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md *.dist composer.* dev-helpers** build**

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: wp-openid
path: build/wp-openid.zip
path: build/wp-openid-siu-upm.zip

- name: Update CHANGELOG
id: changelog
Expand All @@ -53,17 +53,17 @@ jobs:
allowUpdates: true
draft: false
makeLatest: true
name: WP-OpenID - ${{ github.ref_name }}
name: WP-SIU-UPM - ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
artifacts: build/wp-openid.zip
artifacts: build/wp-openid-siu-upm.zip
replacesArtifacts: true

- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
commit_user_name: nicko170 [bot]
commit_user_email: 172472+nicko170[bot]@users.noreply.github.com
commit_user_name: Jenkins DAT-ETSIT
commit_user_email: jenkins-dat-etsit-upm@users.noreply.github.com
file_pattern: CHANGELOG.md
token: ${{ steps.generate_token.outputs.token }}
20 changes: 15 additions & 5 deletions OpenID.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class OpenID
{
private ?string $metadata_url;
private ?string $redirect_uri;
private ?string $client_id;
private ?string $client_secret;
private ?string $default_role;
Expand Down Expand Up @@ -33,6 +34,7 @@ public function __construct()
// General Options
$this->is_network = is_plugin_active_for_network('wp-openid');
$this->metadata_url = defined('WP_OPENID_METADATA_URL') ? WP_OPENID_METADATA_URL : ($this->is_network ? get_site_option('openid_metadata_url') : get_option('openid_metadata_url'));
$this->redirect_uri = defined('WP_OPENID_REDIRECT_URI') ? WP_OPENID_REDIRECT_URI : ($this->is_network ? get_site_option('openid_redirect_uri') : get_option('openid_redirect_uri'));
$this->client_id = defined('WP_OPENID_CLIENT_ID') ? WP_OPENID_CLIENT_ID : ($this->is_network ? get_site_option('openid_client_id') : get_option('openid_client_id'));
$this->client_secret = defined('WP_OPENID_CLIENT_SECRET') ? WP_OPENID_CLIENT_SECRET : ($this->is_network ? get_site_option('openid_client_secret') : get_option('openid_client_secret'));
$this->default_role = defined('WP_OPENID_DEFAULT_ROLE') ? WP_OPENID_DEFAULT_ROLE : ($this->is_network ? get_site_option('openid_default_role') : get_option('openid_default_role'));
Expand Down Expand Up @@ -200,7 +202,7 @@ public function login_redirect(): bool
'response_type' => 'code',
'client_id' => $this->client_id,
'state' => $state['state'],
'redirect_uri' => esc_url(add_query_arg('openid', 'callback', site_url('/wp-login.php'))),
'redirect_uri' => esc_url(add_query_arg('openid', 'callback', $this->redirect_uri)),
'code_challenge' => $code_challenge,
'code_challenge_method' => 'S256',
'scope' => 'openid profile email',
Expand Down Expand Up @@ -290,7 +292,7 @@ private function _get_token(string $code): array
'body' => [
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => esc_url(add_query_arg('openid', 'callback', site_url('/wp-login.php'))),
'redirect_uri' => esc_url(add_query_arg('openid', 'callback', $this->redirect_uri)),
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'code_verifier' => $state['verifier'],
Expand Down Expand Up @@ -416,6 +418,7 @@ public function admin_init(): void
{
// General options
register_setting('openid', 'openid_metadata_url');
register_setting('openid', 'openid_redirect_uri');
register_setting('openid', 'openid_client_id');
register_setting('openid', 'openid_client_secret');
register_setting('openid', 'openid_default_role');
Expand Down Expand Up @@ -624,15 +627,19 @@ public function settings_page(): void
<?php esc_html_e('Step 4', 'openid'); ?>
</h2>
<p>
If your OpenID provider supports provider initiated login, you can use the following settings:
Enter where you want to be redirected after login. By default, it should be <code><?php echo esc_url(add_query_arg('openid', 'login', site_url('/wp-login.php'))) ?></code>
</p>
<table class="form-table">
<tr>
<th scope="row">
<?php esc_html_e('Initiate Login URI', 'openid'); ?>
Redirect URI
</th>
<td>
<code><?php echo esc_url(add_query_arg('openid', 'login', site_url('/wp-login.php'))) ?></code>
<label>
<input type="url" name="openid_redirect_uri"
value="<?php echo esc_url($this->redirect_uri); ?>"
size="40"<?php echo esc_attr(defined('WP_OPENID_REDIRECT_URI') ? ' disabled readonly' : ''); ?>>
</label>
</td>
</tr>
</table>
Expand Down Expand Up @@ -847,6 +854,7 @@ public function save_settings(): void

// Validate and save the settings
update_site_option('openid_metadata_url', esc_url_raw(filter_var($_POST['openid_metadata_url'], FILTER_VALIDATE_URL) ?? '', ['https']));
update_site_option('openid_redirect_uri', esc_url_raw(filter_var($_POST['openid_redirect_uri'], FILTER_VALIDATE_URL) ?? '', ['https']));
update_site_option('openid_client_id', sanitize_text_field($_POST['openid_client_id'] ?? ''));
update_site_option('openid_client_secret', sanitize_text_field($_POST['openid_client_secret'] ?? ''));
update_site_option('openid_default_role', sanitize_text_field($_POST['openid_default_role'] ?? ''));
Expand All @@ -860,12 +868,14 @@ public function deactivate(): void
{
if ($this->is_network) {
delete_site_option('openid_metadata_url');
delete_site_option('openid_redirect_uri');
delete_site_option('openid_client_id');
delete_site_option('openid_client_secret');
delete_site_option('default_role');
delete_site_option('user_mapping');
} else {
delete_option('openid_metadata_url');
delete_option('openid_redirect_uri');
delete_option('openid_client_id');
delete_option('openid_client_secret');
delete_option('openid_default_role');
Expand Down
16 changes: 8 additions & 8 deletions wp-openid.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

/*
Plugin Name: WP OpenID
Plugin URI: https://github.com/nicko170/wp-openid
Description: Simple OpenID authentication for WordPress.
Plugin Name: WP OpenId - SIU UPM
Plugin URI: https://github.com/DAT-ETSIT/wp-siu-upm
Description: SIU UPM authentication for WordPress. Based on nicko170's wp-openid
Version: VERSION
Author: Nick Pratley
Author URI: https://theitdept.au
Author: Pablo Fernández López
Author URI: https://github.com/Pablofl01
Text Domain: openid
Domain Path: /languages
Documentation: https://github.com/nicko170/wp-openid
Documentation: https://github.com/DAT-ETSIT/wp-siu-upm
*/


Expand All @@ -28,9 +28,9 @@
// We only want to run the updater if we are in the admin area.
add_action('admin_init', function () {
GithubUpdater::make()
->repository('nicko170/wp-openid')
->repository('DAT-ETSIT/wp-siu-upm')
->asset_name('wp-openid.zip')
->readme_url('https://raw.githubusercontent.com/nicko170/wp-openid/main/README.md')
->readme_url('https://raw.githubusercontent.com/DAT-ETSIT/wp-siu-upm/main/README.md')
->boot(__FILE__);
});

Expand Down

0 comments on commit 2798ac3

Please sign in to comment.