Open warcooft opened 2 months ago
[!WARNING]
Rate limit exceeded
@warcooft has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 8 seconds before requesting another review.
How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit.How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our [FAQ](https://coderabbit.ai/docs/faq) for further information.Commits
Files that changed from the base of the PR and between 082657b9662aa7815db37b49b2ad09412b601b2f and 28960c2f9d7bb0ebe91c24f3436341458b2b9143.
The changes introduced in the pull request enhance the documentation and functionality of the OAuth library by adding support for Microsoft OAuth. This includes updates to the documentation files to clarify the process of obtaining OAuth keys and integrating Microsoft OAuth. A new MicrosoftOAuth
class has been created to manage Microsoft OAuth 2.0 authentication, providing methods for generating authorization links, fetching access tokens, and retrieving user information.
Files | Change Summary |
---|---|
docs/get_keys.md | Added section for Microsoft keys, improved formatting, and clarified instructions for key acquisition. |
src/Libraries/MicrosoftOAuth.php | Created a new class MicrosoftOAuth to manage Microsoft OAuth 2.0 authentication processes. |
OAuthController
class regarding configuration settings for OAuth directly relate to the new MicrosoftOAuth
class introduced in the main PR, as both involve managing OAuth authentication processes.🐰 In the garden of code, a new path we weave,
With Microsoft OAuth, we joyfully believe.
Keys and tokens, in harmony they play,
A dance of integration, brightening the day.
Hops of delight as users connect,
In this world of OAuth, we all can reflect! 🌼
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Need update : 1- REDME file. 2- Libraries/Basic/ShieldOAuth.php https://github.com/datamweb/shield-oauth/blob/4d31367f366e400aa14419c34614487dad25ed73/src/Libraries/Basic/ShieldOAuth.php#L87-L148
Microsoft oauth by default does not provide avatar in its payload, if we want it we can fetch it from a different endpoint.
example:
private static $API_USER_AVATAR_URL = 'https://graph.microsoft.com/v1.0/me/photos/240x240/$value';
private function getUserAvatarWithToken(): string|null
{
try {
$response = $this->client->request('GET', self::$API_USER_AVATAR_URL, [
'headers' => [
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'image/jpg',
],
'http_errors' => false,
]);
} catch (Exception $e) {
die($e->getMessage());
}
$body = $response->getBody();
$base64 = base64_encode($body);
$avatar = $this->createAvatar($base64);
return $avatar;
}
private function createAvatar(string $base64, string $pathToSave = 'ShieldOauth/avatar/', string|null $newName = null): string|null
{
helper('text');
$decodedBase64 = base64_decode($base64);
if ($decodedBase64 === false) {
return null;
}
$pathToSave .= date('Y/m/');
$newName = $newName ?? 'avatar_' . random_string('alnum', 8) . '.jpg';
if (!is_dir($pathToSave) && !mkdir($pathToSave, 0777, true)) {
return null;
}
if (file_put_contents($pathToSave . $newName, $decodedBase64) === false) {
return null;
}
return $pathToSave . $newName;
}
then in fetchUserInfoWithToken()
protected function fetchUserInfoWithToken(): object
{
try {
$response = $this->client->request('GET', self::$API_USER_INFO_URL, [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => self::$APPLICATION_NAME . '/1.0',
'Authorization' => 'Bearer ' . $this->getToken(),
],
'http_errors' => false,
]);
} catch (Exception $e) {
exit($e->getMessage());
}
$userInfo = json_decode($response->getBody());
$userInfo->email = $userInfo->mail;
$userInfo->avatar = $this->getUserAvatarWithToken(); // add this
return $userInfo;
}
Microsoft oauth by default does not provide avatar in its payload, if we want it we can fetch it from a different endpoint.
See: https://github.com/datamweb/shield-oauth/discussions/106#discussioncomment-9425096
Do you mean we should save the base64 data in the avatar column instead of just saving the file path?
Hi, and thanks for the submitted PR! Could you please look into how other packages(Laravel Socialite, Hybridauth,Python Social Auth,Passport.js) handle avatar management? This information could help us choose the best approach for implementation.
I think the avatar column should be left null, if anyone wants to implement avatar, they can send PR.
Official support for Microsoft services.
If you have any questions feel free to ask. Thanks.
Summary by CodeRabbit
New Features
Documentation