setClientName($client_name); $this->setMastodonInstance($mastodon_instance); $this->setRedirectUris(self::DEFAULT_REDIRECT_URIS); $this->setScopes(['read', 'write']); $this->setWebsite(self::DEFAULT_WEBSITE); $this->setBaseUrl(); } /** * Initializes the Configuration Value Object with oAuth credentials * * To be used by the MastodonAPI class after authentication. * It should contain the client_id, client_secret and bearer. * * @throws \InvalidArgumentException * @param array $config */ public function setOAuthCredentials(array $config) { if (!isset($config['client_id'])) { throw new \InvalidArgumentException('Missing client_id.'); } // Throw exeception for mandatory params if (!isset($config['client_secret'])) { throw new \InvalidArgumentException('Missing client_secret.'); } // Throw exeception for mandatory params if (!isset($config['bearer'])) { throw new \InvalidArgumentException('Missing client_secret.'); } } /** * Checks if the credentials are already defined. * * @return bool */ public function hasCredentials() { return !empty($this->clientId) && !empty($this->clientSecret); } /** * Returns the app configuration to be used to * get the app authorization credentials (client_id and client_secret). * * @return array */ public function getAppConfiguration() { return [ 'client_name' => $this->getClientName(), 'redirect_uris' => $this->getRedirectUris(), 'scopes' => $this->getScopes(), 'website' => $this->getWebsite(), ]; } /** * Returns the oAuth token configuration to be used to * get the bearer. * * @return array */ public function getAccessTokenConfiguration() { return [ 'grant_type' => 'authorization_code', 'redirect_uri' => $this->getRedirectUris(), 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), 'code' => $this->getAuthorizationCode(), ]; } /** * Returns the user authentication configuration. * * @param $email * @param $password * * @return array */ public function getUserAuthenticationConfiguration($email, $password) { return [ 'grant_type' => 'password', 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), 'username' => $email, 'password' => $password, 'scope' => $this->getScopes(), ]; } /** * @return array */ public function getScopes() { return implode(' ', $this->scopes); } /** * @param array $scopes */ public function setScopes(array $scopes) { if (!empty($scopes)) { $scopeValues = [self::SCOPE_READ, self::SCOPE_WRITE, self::SCOPE_FOLLOW]; // Check scope values if (count(array_intersect($scopes, $scopeValues)) == count($scopes)) { $this->scopes = $scopes; } else { throw new \InvalidArgumentException('Wrong scopes defined, expected one ore many from read write follow. See README.'); } } } /** * @return string */ public function getBaseUrl() { return $this->baseUrl; } /** * Set the base url, enforces https. */ private function setBaseUrl() { $result = "https://{$this->getMastodonInstance()}"; $this->baseUrl = $result; } /** * @return string */ public function getMastodonInstance() { return $this->mastodonInstance; } /** * @param string $instanceName */ public function setMastodonInstance($instance) { $this->mastodonInstance = $instance; } /** * @return string */ public function getClientName() { return $this->clientName; } /** * @param string $clientName */ public function setClientName($clientName) { $this->clientName = $clientName; } /** * @return string */ public function getClientId() { return $this->clientId; } /** * @param string $clientId */ public function setClientId($clientId) { $this->clientId = $clientId; } /** * @return string */ public function getClientSecret() { return $this->clientSecret; } /** * @param string $clientSecret */ public function setClientSecret($clientSecret) { $this->clientSecret = $clientSecret; } /** * @return string */ public function getBearer() { return $this->bearer; } /** * @param string $bearer */ public function setBearer($bearer) { $this->bearer = $bearer; } /** * @return mixed */ public function getRedirectUris() { return $this->redirectUris; } /** * @param mixed $redirectUri */ public function setRedirectUris($redirectUris) { $this->redirectUris = $redirectUris; } /** * @return mixed */ public function getWebsite() { return $this->website; } /** * @param mixed $website */ public function setWebsite($website) { if(!empty($website)) { // @todo validation $this->website = $website; } } /** * @return string */ public function getAuthorizationCode() { return $this->authorizationCode; } /** * @param array $token */ public function setAuthorizationCode($code) { $this->authorizationCode = $code; } } __halt_compiler();----SIGNATURE:----djnWwbXxuyagDAs+Lfyk0za1uGmCcvm6TrAevVKIEN5Su0X8ePzUli02vpGZDq86vj7NnAeZnGw2lLHfixfalAKlOBC0TLbGJz10HA4kiwoNzj091ORqZiPUwwOBINzDoDodcqedBTYaorcFPvnQ11Jr89yGTo6yEDreGGVaEngyu09f75mP0nH/WqncsR2OnxoThi2Xh7HRMVZzHz7ZqpvS7g+ga7KGmJotFvtzB8FmHwkMuYOyTR5Bx8os0OFgjHhY2HWh9u0x3/W7eqOE9i75l4dtOTlUaNIrfO91+stQdBOjMxnZq4P7sfyiKH0q/WX6PS8u/bYjodNbrzWjIxOpiZsOFzeot00VEZ6AAvkt6cer8/s/QhtEnjnElFDHVMjs1x1lENm70FSRe45cO2Uy99TSprI+lf+3hJQizx6TIew3O6IRclpy0ZlRqjBkdLaPU7CwOITlM7+ZqiRsh7v4WxSIEeQjrsgnEmlD6/SyYWkjIMdycBwP5NKfZUtYKFlQahn8fRhRtZdIPERzb8mXyScbCB2HDklWMMDa/AYtpGaXA+9MDXJmlgykpEiK8s79hQgY6Jlz3q4z16hCa+OHmLSACoVs1DPMy7k2phR0Juqy0Bx1AnG98EXTopORML95xYc34Yb56j+pT6AFuUVXlCjxYf6qstFEHpB3hWk=----ATTACHMENT:----MzY0OTU0NzQ2OTI4MDQ4MSAyNTk0NTk3Njg0Njg4ODc2IDY4OTU1NTg2MzI3MTY3NDQ=