diff --git a/composer.json b/composer.json index 5655cfb..5e01532 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,23 @@ "email": "franz@develophp.org" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/pipindex/core" + }, + { + "type":"vcs", + "url": "https://github.com/romanzpolski/flarum-ext-shawTheme" + } + ], "support": { "issues": "https://github.com/flarum/core/issues", "source": "https://github.com/flarum/flarum", "docs": "http://flarum.org/docs" }, "require": { - "flarum/core": "^0.1.0", + "flarum/core": "master", "flarum/flarum-ext-akismet": "^0.1.0", "flarum/flarum-ext-approval": "^0.1.0", "flarum/flarum-ext-auth-facebook": "^0.1.0", @@ -39,7 +49,12 @@ "flarum/flarum-ext-sticky": "^0.1.0", "flarum/flarum-ext-subscriptions": "^0.1.0", "flarum/flarum-ext-suspend": "^0.1.0", - "flarum/flarum-ext-tags": "^0.1.0" + "flarum/flarum-ext-tags": "^0.1.0", + "wuethrich44/flarum-ext-sso": "^1.1", + "romanzpolski/flarum-ext-shawTheme": "*@dev", + "sijad/flarum-ext-pages": "dev-master", + "davis/flarum-ext-customfooter": "dev-master", + "avatar4eg/flarum-ext-users-list": "dev-master" }, "require-dev": { "franzl/studio": "^0.11.0" @@ -47,6 +62,6 @@ "config": { "preferred-install": "dist" }, - "minimum-stability": "beta", + "minimum-stability": "dev", "prefer-stable": true } diff --git a/launch.php b/launch.php new file mode 100644 index 0000000..aa21ed5 --- /dev/null +++ b/launch.php @@ -0,0 +1,16 @@ + **Flarum is currently in beta and should not be used in production.** It is being developed openly on GitHub. Check out the [Roadmap](http://flarum.org/roadmap) to follow along with our progress. - -You must have SSH access to a server with **PHP 5.5+** and **MySQL 5.5+**, and install [Composer](https://getcomposer.org). + ``` -composer create-project flarum/flarum . --stability=beta + 'http://localhost:9999', + // Domain of your main site (without http://) + 'root_domain' => 'localhost', + // Create a random key in the api_keys table of your Flarum forum + 'flarum_api_key' => '6cdVzOYGVW', + // Random token to create passwords + 'password_token' => 'NotSecureToken', + // How many days should the login be valid + 'lifetime_in_days' => 14, +]; + ``` -Read the [Installation Guide](http://flarum.org/docs/installation) for more information. +___ +* Last revision on 16/09/2017 +* @aligajani -## Support - -Refer to the [FAQ](http://flarum.org/docs/faq), [Documentation](http://flarum.org/docs), and ask questions on the [Community Forum](http://discuss.flarum.org) or [Gitter Chat](https://gitter.im/flarum/flarum). - -## Contributing - -Flarum is open-source and we would love your help building it! Please read the [Contributing Guide](https://github.com/flarum/flarum/blob/master/CONTRIBUTING.md) to learn how you can help. - -## License - -Copyright (c) 2015 Toby Zerner. Code released under the [MIT License](https://github.com/flarum/flarum/blob/master/LICENSE). diff --git a/sso/SSOController.php b/sso/SSOController.php new file mode 100644 index 0000000..3285bbd --- /dev/null +++ b/sso/SSOController.php @@ -0,0 +1,129 @@ +config = require __DIR__ . '/config.php'; + } + + /** + * Call this method after your user is successfully authenticated. + * + * @param $username + * @param $email + * @param $avatarUrl + */ + public function login($username, $email, $avatarUrl) + { + $password = $this->createPassword($username); + $token = $this->getToken($username, $password); + + if (empty($token)) { + $this->signup($username, $password, $email, $avatarUrl); + $token = $this->getToken($username, $password); + } + + $this->setRememberMeCookie($token); + } + + /** + * Call this method after you logged out your user. + */ + public function logout() + { + $this->removeRememberMeCookie(); + } + + /** + * Redirects a user back to the forum. + * @param $targetUrl + */ + public function redirectToForum($targetUrl) + { + $targetUrl = (!is_null($targetUrl)) ? $targetUrl : ''; + header('Location: ' . $this->config['flarum_url'] . $targetUrl); + die(); + } + + private function createPassword($username) + { + return hash('sha256', $username . $this->config['password_token']); + } + + private function getToken($username, $password) + { + $data = [ + 'identification' => $username, + 'password' => $password, + 'lifetime' => $this->getLifetimeInSeconds(), + ]; + + $response = $this->sendPostRequest('/api/token', $data); + + return isset($response['token']) ? $response['token'] : ''; + } + + private function signup($username, $password, $email, $avatarUrl) + { + $data = [ + "data" => [ + "type" => "users", + "attributes" => [ + "username" => $username, + "password" => $password, + "email" => $email, + "avatarUrl" => $avatarUrl + ] + ] + ]; + + $response = $this->sendPostRequest('/api/users', $data); + + return isset($response['data']['id']); + } + + private function sendPostRequest($path, $data) + { + $data_string = json_encode($data); + + $ch = curl_init($this->config['flarum_url'] . $path); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Content-Length: ' . strlen($data_string), + 'Authorization: Token ' . $this->config['flarum_api_key'] . '; userId=1', + ] + ); + $result = curl_exec($ch); + + return json_decode($result, true); + } + + private function setRememberMeCookie($token) + { + $this->setCookie(self::REMEMBER_ME_KEY, $token, time() + $this->getLifetimeInSeconds()); + } + + private function removeRememberMeCookie() + { + unset($_COOKIE[self::REMEMBER_ME_KEY]); + $this->setCookie(self::REMEMBER_ME_KEY, '', time() - 10); + } + + private function setCookie($key, $token, $time) + { + setcookie($key, $token, $time, '/', $this->config['root_domain']); + } + + private function getLifetimeInSeconds() + { + return $this->config['lifetime_in_days'] * 60 * 60 * 24; + } +} diff --git a/sso/auth.php b/sso/auth.php new file mode 100644 index 0000000..35365f7 --- /dev/null +++ b/sso/auth.php @@ -0,0 +1,16 @@ +email; +$username = $decodedTestData->username; +$avatarUrl = $decodedTestData->avatarUrl; + +$forum = new SSOController(); +$forum->login($username, $email, $avatarUrl); +$forum->redirectToForum($targetUrl); diff --git a/sso/index.php b/sso/index.php new file mode 100644 index 0000000..3db9585 --- /dev/null +++ b/sso/index.php @@ -0,0 +1,216 @@ + + +
+ + + + +A user is logged into members area. Let's demonstrate SSO with Flarum.
+Fake data generated using faker.js
+ +