src/MediaServices/Authentication/AzureAdClient.php
public function acquireTokenWithUserCredentials($resource, $clientId, $username, $password)
    {
        $method = Resources::HTTP_POST;
        $headers = [];
        $queryParams = [];
        $postParameters = [];
        $statusCode = Resources::STATUS_OK;

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_RESOURCE,
            $resource
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_GRANT_TYPE,
            'password'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_SCOPE,
            'openid'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_USERNAME,
            $username
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_PASSWORD,
            $password
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_CLIENT_ID,
            $clientId
        );

        $response = $this->sendHttp(
            $method,
            $headers,
            $queryParams,
            $postParameters,
            Resources::EMPTY_STRING,
            $statusCode
        );

        $data = $this->dataSerializer->unserialize($response->getBody());

        $accessToken = $data['access_token'];
        $expirationTime = time() + intval($data['expires_in']);
        return new AccessToken($accessToken, $expirationTime);
    }
public function acquireTokenWithUserCredentials($resource, $clientId, $username, $password)
    {
        $method = Resources::HTTP_POST;
        $headers = [];
        $queryParams = [];
        $postParameters = [];
        $statusCode = Resources::STATUS_OK;

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_RESOURCE,
            $resource
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_GRANT_TYPE,
            'password'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_SCOPE,
            'openid'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_USERNAME,
            $username
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_PASSWORD,
            $password
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_CLIENT_ID,
            $clientId
        );

        $response = $this->sendHttp(
            $method,
            $headers,
            $queryParams,
            $postParameters,
            Resources::EMPTY_STRING,
            $statusCode
        );

        $data = $this->dataSerializer->unserialize($response->getBody());

        $accessToken = $data['access_token'];
        $expirationTime = time() + intval($data['expires_in']);
        return new AccessToken($accessToken, $expirationTime);
    }
public function acquireTokenWithUserCredentials ( $ resource , $ clientId , $ username , $ password ) { $ method = Resources :: HTTP_POST ; $ headers = [ ] ; $ queryParams = [ ] ; $ postParameters = [ ] ; $ statusCode = Resources :: STATUS_OK ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_RESOURCE , $ resource ) ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_GRANT_TYPE , 'password' ) ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_SCOPE , 'openid' ) ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_USERNAME , $ username ) ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_PASSWORD , $ password ) ; $ postParameters = $ this -> addPostParameter ( $ postParameters , Resources :: OAUTH_CLIENT_ID , $ clientId ) ; $ response = $ this -> sendHttp ( $ method , $ headers , $ queryParams , $ postParameters , Resources :: EMPTY_STRING , $ statusCode ) ; $ data = $ this -> dataSerializer -> unserialize ( $ response -> getBody ( ) ) ; $ accessToken = $ data [ 'access_token' ] ; $ expirationTime = time ( ) + intval ( $ data [ 'expires_in' ] ) ; return new AccessToken ( $ accessToken , $ expirationTime ) ; }
Acquire an Azure AD access token given the username and password

@param string $resource     AzureAD resource asking for access to
@param string $clientId     AzureAD client Id
@param string $username     Username
@param string $password     Password

@return OAuthAccessToken
Acquire an Azure AD access token given the username and password