<commit_before><?php

namespace Mapado\Sdk;

use GuzzleHttp\Client as HttpClient;
use Mapado\Sdk\Model\AccessToken;

class Oauth
{
    const TOKEN_URL = '/oauth/v2/token';
    const HOST = 'https://oauth2.mapado.com';

    /**
     * __construct
     *
     * @param string $clientId
     * @param string $clientSecret
     * @access public
     */
    public function __construct(HttpClient $http, $clientId, $clientSecret)
    {
        $this->clientId = $clientId;
        $this->clientSecret = $clientSecret;

        $this->http = $http;
    }

    /**
     * getClientToken
     *
     * @access public
     * @return AccessToken
     */
    public function getClientToken()
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'client_credentials',
        ]);
    }

    /**
     * getUserToken
     *
     * @param string $username
     * @param string $password
     * @access public
     * @return AccessToken
     */
    public function getUserToken($username, $password)
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'password',
            'username' => $username,
            'password' => $password,
        ]);
    }

    /**
     * getFacebookToken
     *
     * @param string $facebookAccessToken
     * @access public
     * @return AccessToken
     */
    public function getFacebookToken($facebookAccessToken)
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'https://facebookaccesstoken.oauth.mapado.com',
            'facebook_access_token' => $facebookAccessToken,
        ]);
    }

    /**
     * refreshUserToken
     *
     * @param string $refreshToken
     * @access public
     * @return AccessToken
     */
    public function refreshUserToken($refreshToken)
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'refresh_token',
            'refresh_token' => $refreshToken,
        ]);
    }

    /**
     * callOauth
     *<commit_msg>add scope to oauth calls<commit_after><?php

namespace Mapado\Sdk;

use GuzzleHttp\Client as HttpClient;
use Mapado\Sdk\Model\AccessToken;

class Oauth
{
    const TOKEN_URL = '/oauth/v2/token';
    const HOST = 'https://oauth2.mapado.com';

    /**
     * __construct
     *
     * @param string $clientId
     * @param string $clientSecret
     * @access public
     */
    public function __construct(HttpClient $http, $clientId, $clientSecret)
    {
        $this->clientId = $clientId;
        $this->clientSecret = $clientSecret;

        $this->http = $http;
    }

    /**
     * getClientToken
     *
     * @param string $scope
     * @access public
     * @return AccessToken
     */
    public function getClientToken($scope = 'activity:all:read')
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'client_credentials',
            'scope' => $scope,
        ]);
    }

    /**
     * getUserToken
     *
     * @param string $username
     * @param string $password
     * @param string $scope
     * @access public
     * @return AccessToken
     */
    public function getUserToken($username, $password, $scope = 'activity:all:read')
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'password',
            'username' => $username,
            'password' => $password,
            'scope' => $scope,
        ]);
    }

    /**
     * getFacebookToken
     *
     * @param string $facebookAccessToken
     * @param string $scope
     * @access public
     * @return AccessToken
     */
    public function getFacebookToken($facebookAccessToken, $scope = 'activity:all:read')
    {
        return $this->callOauth([
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'https://facebookaccesstoken.oauth.mapado.com',
            'facebook_access_token' => $facebookAccessToken,
            'scope' => $scope,
        ]);
    }

    /**
     * refreshUserToken
     *
     * @param string $refreshToken
     * @param mixed $scope
     * @access public
     * @return AccessToken
     */
    public function refreshUserToken($refreshToken, $scope = null)
    {
        $params = [
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => 'refresh_token',
            'refresh_token' => $refreshToken,
        ];
        if ($scope) {
            $params['scope'] = $scope;
        }
        return $this->callOauth($params);
    }

    /**
     * callOauth
     *
{'fraction_non_alphanumeric': 0.13541255428345836, 'fraction_numerical': 0.0007895775759968417, 'mean_word_length': 1.968365553602812, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4758322', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1496, 'n_words': 282}