/** * Register any application services. * * @return void */ public function register() { $this->app->singleton(MailiumOauthClient::class, function ($app) { $oauthClient = new MailiumOauthClient(null, true); $oauthClient->setClientID(config('mailium-oauth.client_id')); $oauthClient->setClientSecret(config('mailium-oauth.client_secret')); $oauthClient->setScopes(config('mailium-oauth.required_scopes')); $oauthClient->setTokenStoreCallbackFunction(config('mailium-oauth.model') . '::saveOauthToken'); $oauthClient->setRedirectUri(config('mailium-oauth.redirect_uri')); $oauthClient->setAppType(config('mailium-oauth.app_type')); return $oauthClient; }); }
// function to store the token function storeToken($resourceOwner, $token) { $_SESSION['token'] = $token; } // function to remove the token function removeToken($resourceOwner) { unset($_SESSION['token']); } // Start Session session_start(); // Create Oauth client $oauthClient = new MailiumOauthClient(); $oauthClient->setClientID(getenv('MAILIUM_APP_CLIENT_ID')); $oauthClient->setClientSecret(getenv('MAILIUM_APP_CLIENT_SECRET')); $oauthClient->setRedirectUri("http://" . $_SERVER['HTTP_HOST'] . "/oauthcallback.php"); $oauthClient->addScope(MailiumOauthClient::SCOPE_BASIC); $oauthClient->addScope(MailiumOauthClient::SCOPE_CAMPAIGN_READ); $oauthClient->addScope(MailiumOauthClient::SCOPE_SUBSCRIBER_LIST_READ); $oauthClient->setTokenStoreCallbackFunction("storeToken"); print "<h3>Session:</h3>"; print "<pre>"; print_r($_SESSION); print "</pre>"; print "<hr>"; // Token is stored in the session, if we don't have it we should redirect to authorization URL to get the token if (!isset($_SESSION['token'])) { $state = $oauthClient->generateState(); unset($_SESSION['state']); $_SESSION['state'] = $oauthClient->getState();