-
Notifications
You must be signed in to change notification settings - Fork 95
/
WP_Auth0_InitialSetup_ConnectionProfile.php
57 lines (40 loc) · 1.59 KB
/
WP_Auth0_InitialSetup_ConnectionProfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
class WP_Auth0_InitialSetup_ConnectionProfile {
const SETUP_NONCE_ACTION = 'wp_auth0_callback_step1';
protected $a0_options;
protected $domain;
public function __construct( WP_Auth0_Options $a0_options ) {
$this->a0_options = $a0_options;
$this->domain = $this->a0_options->get( 'auth0_server_domain', 'auth0.auth0.com' );
}
public function render( $step ) {
include WPA0_PLUGIN_DIR . 'templates/initial-setup/connection_profile.php';
}
public function callback() {
if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], self::SETUP_NONCE_ACTION ) ) {
wp_nonce_ays( self::SETUP_NONCE_ACTION );
exit;
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'Unauthorized.', 'wp-auth0' ) );
exit;
}
if ( isset( $_REQUEST['apitoken'] ) && ! empty( $_REQUEST['apitoken'] ) ) {
$token = $_REQUEST['apitoken'];
$domain = $_REQUEST['domain'];
$consent_callback = new WP_Auth0_InitialSetup_Consent( $this->a0_options );
$consent_callback->callback_with_token( $domain, $token, null, false );
} else {
$consent_url = $this->build_consent_url();
wp_safe_redirect( $consent_url );
}
exit();
}
public function build_consent_url() {
$callback_url = urlencode( admin_url( 'admin.php?page=wpa0-setup&callback=1' ) );
$client_id = urlencode( get_bloginfo( 'url' ) );
$scope = urlencode( implode( ' ', WP_Auth0_Api_Client::ConsentRequiredScopes() ) );
$url = "https://{$this->domain}/authorize?client_id={$client_id}&response_type=code&redirect_uri={$callback_url}&scope={$scope}&expiration=9999999999";
return $url;
}
}