Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waiting on resolution of https://app.blackbaud.com/support/cases/018662802 #7

Open
github-actions bot opened this issue Mar 14, 2024 · 1 comment
Assignees
Labels
blocked This is blocked by something else bug Something isn't working todo

Comments

@github-actions
Copy link

// TODO waiting on resolution of https://app.blackbaud.com/support/cases/018662802

<?php

namespace GrotonSchool\OAuth2\Client\Provider;

use Exception;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AccessTokenInterface;
use League\OAuth2\Client\Tool\ArrayAccessorTrait;
use Psr\Http\Message\ResponseInterface;

class BlackbaudSKY extends AbstractProvider
{
    use ArrayAccessorTrait;
    public const ACCESS_KEY = "Bb-Api-Subscription-Key";
    public const ACCESS_TOKEN = "access_token";

    public const SESSION_STATE = "oauth2_state";

    public const ARG_AUTH_CODE = "authorization_code";

    public const PARAM_CODE = "code";
    public const PARAM_STATE = "state";

    public const OPT_PARAMS = "params";
    public const OPT_REDIRECT_URI = "redirect_uri";
    public const OPT_AUTH_CODE_CALLBACK = "authorization_code_callback";
    public const OPT_ACCESS_TOKEN_CALLBACK = "access_token_callback";
    public const OPT_ERROR_CALLBACK = "error_callback";

    private $accessKey;

    /** @var AccessToken */
    protected $accessToken;

    public function __construct(array $options = [], array $collaborators = [])
    {
        parent::__construct($options, $collaborators);

        if (empty($options[self::ACCESS_KEY])) {
            throw new Exception("Blackbaud access key required");
        } else {
            $this->accessKey = $options[self::ACCESS_KEY];
        }

        if (!empty($options[self::ACCESS_TOKEN])) {
            $this->accessToken = $options[self::ACCESS_TOKEN];
        }
    }

    public function getBaseAuthorizationUrl()
    {
        return "https://oauth2.sky.blackbaud.com/authorization";
    }

    public function getBaseAccessTokenUrl(array $params)
    {
        return "https://oauth2.sky.blackbaud.com/token";
    }

    public function getBaseApiUrl()
    {
        return "https://api.sky.blackbaud.com";
    }

    public function getResourceOwnerDetailsUrl(AccessToken $token)
    {
        // TODO waiting on resolution of https://app.blackbaud.com/support/cases/018662802
    }

    protected function getDefaultScopes()
    {
        return [];
    }

    protected function checkResponse(ResponseInterface $response, $data)
    {
    }

    protected function createResourceOwner(array $response, AccessToken $token)
    {
    }

    /**
     * Returns authorization headers for the 'bearer' grant.
     *
     * @param  AccessTokenInterface|string|null $token Either a string or an access token instance
     * @return array
     */
    protected function getAuthorizationHeaders($token = null)
    {
        return [
      self::ACCESS_KEY => $this->accessKey,
      "Authorization" => "Bearer " . $token,
    ];
    }

    public function getAccessToken($grant = "", array $options = [])
    {
        if (!empty($grant)) {
            $this->accessToken = parent::getAccessToken($grant, $options);
            return $this->accessToken;
        } elseif (!empty($this->accessToken)) {
            return $this->accessToken->getToken();
        } else {
            throw new Exception("Stored access token or grant type required");
        }
    }

    public function setAccessToken(AccessToken $accessToken)
    {
        $this->accessToken = $accessToken;
    }

    /** @deprecated 0.2.3 externalized to {@link https://github.com/groton-school/appengine-sky-api groton-school/appengine-sky-api} */
    public function endpoint(
        string $path,
        ?AccessToken $token = null
    ): SkyAPIEndpoint {
        if (!$token) {
            if ($this->accessToken) {
                $token = $this->accessToken;
            } else {
                throw new Exception("No access token provided or cached");
            }
        }
        return new SkyAPIEndpoint($this, $path, $token);
    }
}
@github-actions github-actions bot added the todo label Mar 14, 2024
@battis battis added bug Something isn't working blocked This is blocked by something else labels Mar 14, 2024
@battis
Copy link
Member

battis commented Mar 14, 2024

Blocked by this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This is blocked by something else bug Something isn't working todo
Projects
None yet
Development

No branches or pull requests

1 participant