Differential D9431 Diff 22523 src/applications/auth/management/PhabricatorAuthManagementRefreshWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/management/PhabricatorAuthManagementRefreshWorkflow.php
| Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | public function execute(PhutilArgumentParser $args) { | ||||
| if (strlen($domain)) { | if (strlen($domain)) { | ||||
| $query->withAccountDomains(array($domain)); | $query->withAccountDomains(array($domain)); | ||||
| } | } | ||||
| $accounts = $query->execute(); | $accounts = $query->execute(); | ||||
| if (!$accounts) { | if (!$accounts) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht("No accounts match the arguments!")); | pht('No accounts match the arguments!')); | ||||
| } else { | } else { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "%s\n", | "%s\n", | ||||
| pht( | pht( | ||||
| "Found %s account(s) to refresh.", | 'Found %s account(s) to refresh.', | ||||
| new PhutilNumber(count($accounts)))); | new PhutilNumber(count($accounts)))); | ||||
| } | } | ||||
| $providers = PhabricatorAuthProvider::getAllEnabledProviders(); | $providers = PhabricatorAuthProvider::getAllEnabledProviders(); | ||||
| foreach ($accounts as $account) { | foreach ($accounts as $account) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "%s\n", | "%s\n", | ||||
| pht( | pht( | ||||
| "Refreshing account #%d (%s/%s).", | 'Refreshing account #%d (%s/%s).', | ||||
| $account->getID(), | $account->getID(), | ||||
| $account->getAccountType(), | $account->getAccountType(), | ||||
| $account->getAccountDomain())); | $account->getAccountDomain())); | ||||
| $key = $account->getProviderKey(); | $key = $account->getProviderKey(); | ||||
| if (empty($providers[$key])) { | if (empty($providers[$key])) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "> %s\n", | "> %s\n", | ||||
| pht("Skipping, provider is not enabled or does not exist.")); | pht('Skipping, provider is not enabled or does not exist.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $provider = $providers[$key]; | $provider = $providers[$key]; | ||||
| if (!($provider instanceof PhabricatorAuthProviderOAuth2)) { | if (!($provider instanceof PhabricatorAuthProviderOAuth2)) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "> %s\n", | "> %s\n", | ||||
| pht("Skipping, provider is not an OAuth2 provider.")); | pht('Skipping, provider is not an OAuth2 provider.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $adapter = $provider->getAdapter(); | $adapter = $provider->getAdapter(); | ||||
| if (!$adapter->supportsTokenRefresh()) { | if (!$adapter->supportsTokenRefresh()) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "> %s\n", | "> %s\n", | ||||
| pht("Skipping, provider does not support token refresh.")); | pht('Skipping, provider does not support token refresh.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $refresh_token = $account->getProperty('oauth.token.refresh'); | $refresh_token = $account->getProperty('oauth.token.refresh'); | ||||
| if (!$refresh_token) { | if (!$refresh_token) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "> %s\n", | "> %s\n", | ||||
| pht("Skipping, provider has no stored refresh token.")); | pht('Skipping, provider has no stored refresh token.')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "+ %s\n", | "+ %s\n", | ||||
| pht( | pht( | ||||
| "Refreshing token, current token expires in %s seconds.", | 'Refreshing token, current token expires in %s seconds.', | ||||
| new PhutilNumber( | new PhutilNumber( | ||||
| $account->getProperty('oauth.token.access.expires') - time()))); | $account->getProperty('oauth.token.access.expires') - time()))); | ||||
| $token = $provider->getOAuthAccessToken($account, $force_refresh = true); | $token = $provider->getOAuthAccessToken($account, $force_refresh = true); | ||||
| if (!$token) { | if (!$token) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "* %s\n", | "* %s\n", | ||||
| pht('Unable to refresh token!')); | pht('Unable to refresh token!')); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "+ %s\n", | "+ %s\n", | ||||
| pht( | pht( | ||||
| "Refreshed token, new token expires in %s seconds.", | 'Refreshed token, new token expires in %s seconds.', | ||||
| new PhutilNumber( | new PhutilNumber( | ||||
| $account->getProperty('oauth.token.access.expires') - time()))); | $account->getProperty('oauth.token.access.expires') - time()))); | ||||
| } | } | ||||
| $console->writeOut("%s\n", pht("Done.")); | $console->writeOut("%s\n", pht('Done.')); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||