/* GetUserInfo convenience function - Returns user's profile information from Amazon using the access token returned by the Button widget.

@see http://login.amazon.com/website Step 4
@param $accessToken [String]
353947
public function getUserInfo($accessToken)
    {
        // Get the correct Profile Endpoint URL based off the country/region provided in the config['region']
        $this->profileEndpointUrl();

        if (empty($accessToken)) {
            throw new \InvalidArgumentException('Access Token is a required parameter and is not set');
        }

        // To make sure double encoding doesn't occur decode first and encode again.
        $accessToken = urldecode($accessToken);
        $url          = $this->profileEndpoint . '/auth/o2/tokeninfo?access_token=' . $this->urlEncode($accessToken);

        $httpCurlRequest = new HttpCurl($this->config);

        $response = $httpCurlRequest->httpGet($url);
        $data       = json_decode($response);

        // Ensure that the Access Token matches either the supplied Client ID *or* the supplied App ID
        // Web apps and Mobile apps will have different Client ID's but App ID should be the same
        // As long as one of these matches, from a security perspective, we have done our due diligence
        if (($data->aud != $this->config['client_id']) && ($data->app_id != $this->config['app_id'])) {
            // The access token does not belong to us
            throw new \Exception('The Access Token belongs to neither your Client ID nor App ID');
        }

        // Exchange the access token for user profile
        $url             = $this->profileEndpoint . '/user/profile';
        $httpCurlRequest = new HttpCurl($this->config);

        $httpCurlRequest->setAccessToken($accessToken);
        $httpCurlRequest->setHttpHeader();
        $response = $httpCurlRequest->httpGet($url);

        $userInfo = json_decode($response, true);
        return $userInfo;
    }
1356758
public function getOpenId(AccessToken $token)
    {
        $request = $this->getAuthenticatedRequest(self::METHOD_GET, $this->domain.'/oauth2.0/me?access_token='.(string)$token);

        $response = $this->getResponse($request);

        return isset($response['openid']) ? $response['openid'] : null;
    }
1081597
public function getProfileCharacters($accessToken = null, array $options = [])
    {
        if (null === $accessToken) {
            $options['access_token'] = $this->blizzardClient->getAccessToken();
        } else {
            $options['access_token'] = $accessToken;
        }

        return $this->request('/user/characters', $options);
    }
464903
public function getUserInfo($accessToken, $openid)
    {
        $apiUrl = 'https://api.weixin.qq.com/sns/userinfo';

        if ($result = $this->_curl($apiUrl, [
            'access_token' => $accessToken,
            'openid' => $openid,
            'lang' => 'zh_CN',
        ])) {
            unset($result['errcode'], $result['errmsg']);
            return $result;
        } else {
            return null;
        }
    }
628437
protected function getAccessToken(string $tokenName = null): ?AccessToken
    {
        $cacheKey = $this->creteCacheKey($this->config->getKey($tokenName));
        $item = $this->pool->getItem($cacheKey);

        if (!$item->isHit()) {
            return null;
        }

        return $item->get();
    }
787874
public static function getUsernameFromAccessToken( $accesstoken ) {
		$users = self::getUsers();
		foreach( $users as $username => $user ) {
			if ( $user['at'] === $accesstoken ) {
				return $username;
			}
		}
		return null;
	}
119545
public function getUserEmotes($userIdentifier, $accessToken)
    {
        if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) {
            throw new InvalidIdentifierException('user');
        }

        return $this->get(sprintf('users/%s/emotes', $userIdentifier), [], $accessToken);
    }
1368047
protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken){
		// Send post request to authentication service
		$params = array(
			'client_id' => $this->getConfig()->getClientId(),
			'refresh_token' => $refreshToken->getRefreshToken(),
			'grant_type' => 'refresh_token',
		);
		$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
		$output = $response['output'];
		$httpcode = $response['code'];
		
		switch($httpcode){
			case "200" : 
				$responseObject = json_decode($output);
				if(isset($responseObject->error)){
					// an error occured, the RefreshToken is most likely invalid
					// delete RefreshToken to retrieve new one on next request
					$this->getConfig()->getStorage()->deleteRefreshToken();
					return null;
				}
				// create access token and save it
				$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
				$this->getConfig()->getStorage()->saveAccessToken($accessToken);
				return $accessToken;
		}
		return null;
	}
373128
public static function info($access_token)
    {
        $opts = array('http' => array(
            'method'  => 'GET'
        ));

        $url = self::$clef_base_url."info?access_token=".$access_token;

        // exchange the oauth token for the user's info
        $context  = stream_context_create($opts);
        $response = file_get_contents($url, false, $context);

        if (!$response) {
            $response = json_decode($response, true);

            return $response;
        }

        return false;
    }
664129
@Override
  @Transactional(readOnly = true)
  @RunAsSystem
  public UserDetails findUserByToken(String token) {
    Token molgenisToken = getMolgenisToken(token);
    return userDetailsService.loadUserByUsername(molgenisToken.getUser().getUsername());
  }
760465
protected function getExtraParams(AccessTokenEntityInterface $accessToken)
    {

        $user = User::where( 'id', $accessToken->getUserIdentifier() )->first();

        if ( $user->ehr_pid &&
            $user->connection ) {
            $patientRepo = new PatientRepository();
            $patientRepo->setConnection( $user->connection );
            $patient = $patientRepo->findByPid( $user->ehr_pid );
            if ( $patient->getStatus() == 'active' ) {
                $user->activeLoginCount = $user->activeLoginCount + 1;
            }
        }

        $user->loginCount = $user->loginCount + 1;
        $user->save();

        // Custom parameters for /signin can be added here
        $response = ['firstTimeLogin' => 0 ];
        if ( $user->loginCount == 1 ) {
            $response = ['firstTimeLogin' => 1 ];
        }

        $response = ['firstTimeLoginActive' => 0 ];
        if ( $user->activeLoginCount == 1 ) {
            $response = ['firstTimeLoginActive' => 1 ];
        }

        return $response;
    }
608248
public static function fetch( $accessToken, $authCheck = true )
    {
        $tokenInfo = null;
        $session = ezcPersistentSessionInstance::get();
        $q = $session->createFindQuery( __CLASS__ );
        $e = $q->expr;

        $q->innerJoin( 'ezprest_clients', 'ezprest_token.client_id', 'ezprest_clients.client_id' );
        if ( $authCheck )
        {
            $q->innerJoin( 'ezprest_authorized_clients', $e->lAnd( $e->eq( 'ezprest_authorized_clients.rest_client_id', 'ezprest_clients.id' ),
                                                                   $e->eq( 'ezprest_authorized_clients.user_id', 'ezprest_token.user_id' ) ) );
        }

        $q->where( $q->expr->eq( 'ezprest_token.id', $q->bindValue( $accessToken ) ) );
        $tokenInfo = $session->find( $q, 'ezpRestToken' );
        if ( !empty( $tokenInfo ) )
        {
            $tokenInfo = array_shift( $tokenInfo );
        }
        else // Empty array. For consistency in result, cast it to null
        {
            $tokenInfo = null;
        }

        return $tokenInfo;
    }
704045
public function verifyAccessToken($accessToken)
    {
        $jwtPayload = $this->decodeAccessToken($accessToken);

        $expectedIss = sprintf('https://cognito-idp.%s.amazonaws.com/%s', $this->region, $this->userPoolId);
        if ($jwtPayload['iss'] !== $expectedIss) {
            throw new TokenVerificationException('invalid iss');
        }

        if ($jwtPayload['token_use'] !== 'access') {
            throw new TokenVerificationException('invalid token_use');
        }

        if ($jwtPayload['exp'] < time()) {
            throw new TokenExpiryException('invalid exp');
        }

        return $jwtPayload['username'];
    }
1263992
function getAccountInfoByUsername($username)
    {
        $response = $this->call( new Command\AccountInfo($username, Command\AccountInfo::TYPE_USERNAME) );
        if ( $ex = $response->hasException() )
            throw $ex;

        $r = $response->expected();
        $r = ($r instanceof iDataEntity) ? $r->get('result') : $r;
        return $r;
    }
229906
function findUserFromAccessToken(accessToken, UserModel) {

    if (!accessToken) return null;

    return UserModel.findById(accessToken.userId).then((user) => {
        if (!user) return Promise.reject('No user with this access token was found.');
        return Promise.resolve(user);
    });
}
1249003
protected function getAccessToken($oauthToken)
    {
        if (null === $token = $this->app['repo.api-oauth-tokens']->find($oauthToken)) {
            return null;
        }

        return [
            'scope'       => $token->getScope(),
            'expires'     => $token->getExpires(),
            'client_id'   => $token->getAccount()->getApplication()->getClientId(),
            'session_id'  => $token->getSessionId(),
            'revoked'     => (int) $token->getAccount()->isRevoked(),
            'usr_id'      => $token->getAccount()->getUser()->getId(),
            'oauth_token' => $token->getOauthToken(),
        ];
    }
1303910
public function get_user_info( $access_token ) {
		$contents = $this->get_contents( 'user_info_url', [ 'access_token' => $access_token ] );
		$info     = @json_decode( $contents, true );
		if ( empty( $info ) ) {
			$this->app->log( 'social response error', [
				'$contents' => $contents,
				'$info'     => $info,
			] );

			return null;
		}

		return $info;
	}