diff --git a/classes/Auth0Adapter.php b/classes/Auth0Adapter.php new file mode 100644 index 0000000..bdb0c9f --- /dev/null +++ b/classes/Auth0Adapter.php @@ -0,0 +1,46 @@ +oAuth->request('/userinfo'); + $result = $JSON->decode($response); + + if( !empty($result['username']) ) + { + $data['user'] = $result['username']; + } + else + { + $data['user'] = isset($result['name']) ? $result['name'] : $result['email']; + } + $data['name'] = isset($result['name']) ? $result['name'] : $result['email']; + $data['mail'] = $result['email']; + + return $data; + } + + /** + * Access to user and his email addresses + * + * @return array + */ + public function getScope() { + return array(Auth0::SCOPE_OPENID); + } + +} diff --git a/conf/default.php b/conf/default.php index dc61391..f27c5e5 100644 --- a/conf/default.php +++ b/conf/default.php @@ -5,6 +5,9 @@ * @author Andreas Gohr */ +$conf['auth0-key'] = ''; +$conf['auth0-secret'] = ''; +$conf['auth0-domain'] = ''; $conf['custom-redirectURI'] = ''; $conf['facebook-key'] = ''; $conf['facebook-secret'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index 58f21f1..3914958 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -26,6 +26,9 @@ public function html(&$plugin, $echo = false) { } $meta['info'] = array('plugin_oauth'); +$meta['auth0-key'] = array('string'); +$meta['auth0-secret'] = array('string'); +$meta['auth0-domain'] = array('string'); $meta['custom-redirectURI'] = array('string','_caution' => 'warning'); $meta['facebook-key'] = array('string'); $meta['facebook-secret'] = array('string'); @@ -43,6 +46,7 @@ public function html(&$plugin, $echo = false) { $meta['singleService'] = array('multichoice', '_choices' => array( '', + 'Auth0', 'Google', 'Facebook', 'Github', diff --git a/helper.php b/helper.php index db91b9b..e049fff 100644 --- a/helper.php +++ b/helper.php @@ -20,7 +20,7 @@ class helper_plugin_oauth extends DokuWiki_Plugin { public function loadService(&$servicename) { $id = getID(); // $ID isn't set in trustExternal, yet - $servicename = preg_replace('/[^a-zA-Z_]+/', '', $servicename); + $servicename = preg_replace('/[^a-zA-Z0-9_]+/', '', $servicename); if(!$servicename) return null; require_once(__DIR__.'/phpoauthlib/src/OAuth/bootstrap.php'); diff --git a/lang/en/settings.php b/lang/en/settings.php index 0c6014b..e6e3631 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -8,6 +8,9 @@ $lang['info'] = 'Redirect URI to use when configuring the applications'; $lang['custom-redirectURI'] = 'Use the following custom redirect URI'; +$lang['auth0-key'] = 'The Client ID of your registered Auth0 application'; +$lang['auth0-secret'] = 'The Client Secret of your registered Auth0 application'; +$lang['auth0-domain'] = 'The Domain of your registered Auth0 account'; $lang['facebook-key'] = 'The App ID of your registered Facebook application'; $lang['facebook-secret'] = 'The App Secret of your registered Facebook application'; $lang['github-key'] = 'The Client ID of your registered Github application'; diff --git a/phpoauthlib/src/OAuth/OAuth2/Service/Auth0.php b/phpoauthlib/src/OAuth/OAuth2/Service/Auth0.php new file mode 100644 index 0000000..dbe2a95 --- /dev/null +++ b/phpoauthlib/src/OAuth/OAuth2/Service/Auth0.php @@ -0,0 +1,103 @@ +domain = $hlp->getConf('auth0-domain'); + + if (null === $baseApiUri) { + $this->baseApiUri = new Uri("https://{$this->domain}/"); + } + } + + protected function getAuthorizationMethod() + { + return static::AUTHORIZATION_METHOD_HEADER_BEARER; + } + + /** + * {@inheritdoc} + */ + public function getAuthorizationEndpoint() + { + return new Uri("https://{$this->domain}/authorize/"); + } + + /** + * {@inheritdoc} + */ + public function getAccessTokenEndpoint() + { + return new Uri("https://{$this->domain}/oauth/token/"); + } + + /** + * {@inheritdoc} + */ + protected function parseAccessTokenResponse($responseBody) + { + $JSON = new \JSON(JSON_LOOSE_TYPE); + $data = $JSON->decode($responseBody); + + if (null === $data || !is_array($data)) { + throw new TokenResponseException('Unable to parse response.'); + } elseif (isset($data['error'])) { + throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); + } + + $token = new StdOAuth2Token(); + $token->setAccessToken($data['access_token']); + + if (isset($data['expires'])) { + $token->setLifeTime($data['expires']); + } + + if (isset($data['refresh_token'])) { + $token->setRefreshToken($data['refresh_token']); + unset($data['refresh_token']); + } + + unset($data['access_token']); + unset($data['expires']); + + $token->setExtraParams($data); + + return $token; + } + + public function getDialogUri($dialogPath, array $parameters) + { + if (!isset($parameters['redirect_uri'])) { + throw new Exception("Redirect uri is mandatory for this request"); + } + + $parameters['client_id'] = $this->credentials->getConsumerId(); + $baseUrl = "https://{$this->domain}/authorize/"; + $query = http_build_query($parameters); + return new Uri($baseUrl . '?' . $query); + } +} diff --git a/style.less b/style.less index be68752..e32485e 100644 --- a/style.less +++ b/style.less @@ -27,6 +27,14 @@ padding-left: (20px+24px); } + a.plugin_oauth_Auth0 { + .plugin_oauth_button(#d0d2d3); + background-image: url(https://cdn.auth0.com/styleguide/1.0.0/img/badge.png); + padding-left: (20px+24px); + background-size: 22px 24px; + color:#5c666f; + } + a.plugin_oauth_Google { .plugin_oauth_button(#DC4A38); background-image: url(images/google.png);