Skip to content

Commit

Permalink
add Gitee Provider (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhao authored Nov 24, 2021
1 parent 3c3a3da commit 1607bc8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p align="center">Socialite is an <a href="https://oauth.net/2/">OAuth2</a> Authentication tool. It is inspired by <a href="https://github.com/laravel/socialite">laravel/socialite</a>, You can easily use it in any PHP project. <a href="/README_CN.md">中文文档</a></p>

<p align="center">This tool now supports platforms such as Facebook, GitHub, Google, LinkedIn, Outlook, QQ, Tapd, Alipay, Taobao, Baidu, DingTalk, Weibo, WeChat, Douyin, Feishu, Douban, WeWork, Tencent Cloud, Line.</p>
<p align="center">This tool now supports platforms such as Facebook, GitHub, Google, LinkedIn, Outlook, QQ, Tapd, Alipay, Taobao, Baidu, DingTalk, Weibo, WeChat, Douyin, Feishu, Douban, WeWork, Tencent Cloud, Line, Gitee.</p>

[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me-button-s.svg)](https://github.com/sponsors/overtrue)

Expand Down Expand Up @@ -577,7 +577,7 @@ $user = $socialite->userFromToken($accessToken);
- [飞书 - 授权说明](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM)
- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093)
- [Line - OAuth 2.0](https://developers.line.biz/en/docs/line-login/integrate-line-login/)

- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)

[![Sponsor me](https://raw.githubusercontent.com/overtrue/overtrue/master/sponsor-me.svg)](https://github.com/sponsors/overtrue)

Expand Down
3 changes: 2 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<p align="center">Socialite 是一个 <a href="https://oauth.net/2/">OAuth2</a> 认证工具。 它的灵感来源于 <a href="https://github.com/laravel/socialite">laravel/socialite</a>, 你可以很轻易的在任何 PHP 项目中使用它。</p>

<p align="center">该工具现已支持平台有:Facebook,Github,Google,Linkedin,Outlook,QQ,TAPD,支付宝,淘宝,百度,钉钉,微博,微信,抖音,飞书,豆瓣,企业微信,腾讯云,Line。</p>
<p align="center">该工具现已支持平台有:Facebook,Github,Google,Linkedin,Outlook,QQ,TAPD,支付宝,淘宝,百度,钉钉,微博,微信,抖音,飞书,豆瓣,企业微信,腾讯云,Line,Gitee。</p>

- [版本要求](#版本要求)
- [安装](#安装)
Expand Down Expand Up @@ -595,6 +595,7 @@ $user = $socialite->userFromToken($accessToken);
- [飞书 - 授权说明](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM)
- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093)
- [Line - OAuth 2.0](https://developers.line.biz/en/docs/line-login/integrate-line-login/)
- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)



Expand Down
65 changes: 65 additions & 0 deletions src/Providers/Gitee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php


namespace Overtrue\Socialite\Providers;


use Overtrue\Socialite\User;

class Gitee extends Base
{
public const NAME = 'gitee';

protected string $expiresInKey = 'expires_in';

protected string $accessTokenKey = 'access_token';

protected string $refreshTokenKey = 'refresh_token';

protected array $scopes = ['user_info'];


protected function getAuthUrl(): string
{
return $this->buildAuthUrlFromBase('https://gitee.com/oauth/authorize');
}

protected function getTokenUrl(): string
{
return 'https://gitee.com/oauth/token';
}

protected function getUserByToken(string $token): array
{
$userUrl = 'https://gitee.com/api/v5/user';
$response = $this->getHttpClient()->get(
$userUrl,
[
'query' => ['access_token' => $token],
]
);
return \json_decode($response->getBody()->getContents(), true) ?? [];
}

protected function mapUserToObject(array $user): User
{
return new User([
'id' => $user['id'] ?? null,
'nickname' => $user['login'] ?? null,
'name' => $user['name'] ?? null,
'email' => $user['email'] ?? null,
'avatar' => $user['avatar_url'] ?? null,
]);
}

protected function getTokenFields(string $code): array
{
return [
'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'code' => $code,
'redirect_uri' => $this->redirectUrl,
'grant_type' => 'authorization_code',
];
}
}
1 change: 1 addition & 0 deletions src/SocialiteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SocialiteManager implements FactoryInterface
Providers\DingTalk::NAME => Providers\DingTalk::class,
Providers\OpenWeWork::NAME => Providers\OpenWeWork::class,
Providers\Line::NAME => Providers\Line::class,
Providers\Gitee::NAME => Providers\Gitee::class,
];

public function __construct(array $config)
Expand Down

0 comments on commit 1607bc8

Please sign in to comment.