-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Switch to proxy field is a breaking change #22
Comments
Ah, very sorry about that, I didn't consider the breaking change in that change. I'll see if I can amend that. Would you be up for sharing your current custom client class? |
Not a problem Josh, it is unreleased yet, so just wanted to highlight it. Sure, our main integration class just extends the Microsoft Graph provider to modify the authorize/access endpoints as it must be pointed to our tenant ID and not the general Microsoft one. All I need to do is modify our settings HTML part as that's where the issue is. The original code was based off the original integration class mainly. <?php
/**
* Nottingham College Module for Craft CMS 5.x
*
* @link https://www.nottinghamcollege.ac.uk
* @copyright Copyright (c) 2024 Nottingham College
*/
namespace modules\nottinghamcollegeapi\integrations\consume;
use Craft;
use verbb\consume\base\OAuthClient;
use modules\nottinghamcollegeapi\integrations\oauth\providers\MicrosoftGraph as MicrosoftGraphProvider;
/**
* Consume Microsoft Graph OAuth Provider
*
* @author Nottingham College
* @package NottinghamCollegeApi
* @since 1.0.0
*
* @property-read null|string $primaryColor
* @property-read null|string $icon
* @property-read null|string $settingsHtml
*/
class MicrosoftGraph extends OAuthClient
{
// Static Methods
// =========================================================================
public static function displayName(): string
{
return 'Microsoft Graph';
}
public static function getOAuthProviderClass(): string
{
return MicrosoftGraphProvider::class;
}
// Properties
// =========================================================================
public static string $providerHandle = 'Microsoft Graph';
// Public Methods
// =========================================================================
public function getPrimaryColor(): ?string
{
return '#5e5e5e';
}
public function getIcon(): ?string
{
return '<svg fill="currentColor" viewBox="0 0 24 24"><path d="M0 0v11.408h11.408V0zm12.594 0v11.408H24V0zM0 12.594V24h11.408V12.594zm12.594 0V24H24V12.594z"></path></svg>';
}
public function getSettingsHtml(): ?string
{
return Craft::$app->getView()->renderTemplate('nottingham-college-api/consume/oauth/microsoft-graph', [
'client' => $this,
]);
}
} Then our main provider class with the customisations needed on urlAuthorize and urlAuthorizeToken <?php
/**
* Nottingham College Module for Craft CMS 5.x
*
* @link https://www.nottinghamcollege.ac.uk
* @copyright Copyright (c) 2014 Nottingham College
*/
namespace modules\nottinghamcollegeapi\integrations\oauth\providers;
use League\OAuth2\Client\Token\AccessToken;
use verbb\auth\models\Token;
use verbb\auth\providers\Microsoft as MicrosoftProvider;
/**
* Microsoft Graph OAuth Provider
*
* @author Nottingham College
* @package NottinghamCollegeApi
* @since 1.0.1
*/
class MicrosoftGraph extends MicrosoftProvider
{
// Properties
// =========================================================================
/**
* @var array|string[]
*/
public array $defaultScopes = ['openid', 'email', 'profile'];
/**
* @var string
*/
protected string $urlAuthorize = 'https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize';
/**
* @var string
*/
protected string $urlAccessToken = 'https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token';
/**
* @var string
*/
protected string $urlResourceOwnerDetails = 'https://graph.microsoft.com/v1.0/me';
/**
* @param Token|null $token
* @return array
*/
public function getApiRequestQueryParams(?Token $token): array
{
return [];
}
/**
* @param $token
* @return string[]
*/
protected function getAuthorizationHeaders($token = null): array
{
return [
'Authorization' => $token instanceof AccessToken ? sprintf('Bearer %s', $token->getToken()) : '',
];
}
/**
* @param array $response
* @param AccessToken $token
* @return MicrosoftResourceOwner
*/
protected function createResourceOwner(array $response, AccessToken $token): MicrosoftResourceOwner
{
return new MicrosoftResourceOwner($response);
}
/**
* @return string
*/
protected function getScopeSeparator(): string
{
return ' ';
}
} |
From quick testing the change is relatively simple I believe, just: public function getSettingsHtml(): ?string
{
$variables = $this->getSettingsHtmlVariables();
return Craft::$app->getView()->renderTemplate('nottingham-college-api/consume/oauth/microsoft-graph', $variables);
} |
That should indeed be all you need to change, but just trying to replicate the error with your classes, but nothing yet... In any case, I'll be sure to add a note, but it shouldn't be a breaking change. |
Ah OK, that's odd, I had it happen on both dev and live straight away. For reference, the contents of {% include 'consume/clients/oauth/_oauth' %} |
Fixed for the next release. To get this early, run |
Thanks! I have updated our custom OAuth client to be compatible for 2.0.1 and above. |
Describe the bug
Happy Christmas!
Since using dev-craft-5 for the latest changes, I got a stacktrace on a custom OAuth client am getting this stack trace. I believe it is due to 8673272
I can update our client, but on the next release it might be worth flagging in the change logs as a breaking change, as without modifying our custom OAuth integration it breaks viewing the client in the CP.
It is due to the update for the macro being used for proxy URL I believe.
Steps to reproduce
craft\web\twig\Extension::mergeFilter(): Argument #1 ($arr1) must be of type Traversable|array, null given
will occur when viewing the client CP settingsCraft CMS version
5.5.7
Plugin version
dev-craft-5
Multi-site?
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: