Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

/vendor/
.idea/
.phpunit.*
composer.lock
composer.lock
/test/Web/
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
PHP 版 JustAuth

## TODO
- [x] 先能用
- [x] 支持 GITEE 平台
- [x] 支持 GITHUB 平台
- [x] 支持 微博 平台
- [ ] 支持 OSChina 平台
- [ ] 支持 百度 平台
- [ ] 支持 抖音 平台
- [ ] 支持 钉钉 平台
- [x] 先能用
- [x] 支持 GITEE 平台
- [x] 支持 GITHUB 平台
- [x] 支持 OSChina 平台
- [x] 支持 StackOverflow 平台
- [x] 支持 钉钉 平台
- [x] 支持 百度 平台
- [x] 支持 微博 平台
- [x] 支持 抖音 平台
- [x] 支持 QQ 平台
- [ ] 支持 微信 平台
- [ ] 支持 华为 平台
- [ ] 支持 Google 平台
- [ ] 支持 Coding 平台
- [ ] 支持 腾讯云开发者平台 平台
- [ ] 支持 QQ 平台
- [ ] 支持 微信 平台
- [ ] 支持 淘宝 平台
- [ ] 支持 Google 平台


# JustAuth 项目一览

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pfinal/justauth-php",
"description": "description",
"description": "library of third-party authorized login",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
Expand All @@ -26,7 +26,9 @@
"psr-4": {
"JustAuth\\": "src/"
},
"files": []
"files": [
"src/helper.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
77 changes: 63 additions & 14 deletions config/oauth.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
<?php
return [
'github' => [
'client_id'=>env('GITHUB_CLIENT_ID','f4687fdd6801354516b3'),
'redirect_url'=>env('GITHUB_CALLBACK','dev.local.justauth.cn/test/Github/index.php'),
'client_secret'=>env('GITHUB_SECRET','03201d93b38f7eac722899420aaa35e6f375a8c4'),
],
'gitee' => [
'client_id'=>env('GITEE_CLIENT_ID',''),
'redirect_url'=>env('GITEE_CALLBACK',''),
'client_secret'=>env('GITEE_SECRET',''),
],
'weibo' => [
'client_id'=>env('WEIBO_CLIENT_ID',''),
'redirect_url'=>env('WEIBO_CALLBACK',''),
'client_secret'=>env('WEIBO_SECRET',''),
'github' => [
'client_id' => env('GITHUB_CLIENT_ID', ''),
'redirect_uri' => env('GITHUB_CALLBACK', ''),
'client_secret' => env('GITHUB_SECRET', ''),
],
'gitee' => [
'client_id' => env('GITEE_CLIENT_ID', ''),
'client_secret' => env('GITEE_SECRET', ''),
'redirect_uri' => env('GITEE_CALLBACK', ''),
],
'weibo' => [
'client_id' => env('WEIBO_CLIENT_ID', ''),
'redirect_url' => env('WEIBO_CALLBACK', ''),
'client_secret' => env('WEIBO_SECRET', ''),
],
'douyin' => [
'client_id' => env('WEIBO_CLIENT_ID', ''),
'redirect_uri' => env('WEIBO_CALLBACK', ''),
'client_secret' => env('WEIBO_SECRET', ''),
'state' => env('WEIBO_STATE', ''),
],
'weixin' => [
'client_id' => env('WEIXIN_CLIENT_ID', ''),
'redirect_uri' => env('WEIXIN_CALLBACK', ''),
'client_secret' => env('WEIXIN_SECRET', ''),
],
'qq' => [
'client_id' => env('QQ_CLIENT_ID', ''),
'redirect_uri' => env('QQ_CALLBACK', ''),
'client_secret' => env('QQ_SECRET', ''),
],
'huawei' => [
'client_id' => env('HUAWEI_CLIENT_ID', ''),
'redirect_uri' => env('HUAWEI_CALLBACK', ''),
'client_secret' => env('HUAWEI_SECRET', ''),
'scope' => env('HUAWEI_SECRET', ''),
'state' => env('HUAWEI_STATE', ''),
],
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID', ''),
'redirect_uri' => env('GOOGLE_CALLBACK', ''),
'client_secret' => env('GOOGLE_SECRET', ''),
],
'baidu' => [
'client_id' => env('BAIDU_CLIENT_ID', ''),
'redirect_uri' => env('BAIDU_CALLBACK', ''),
'client_secret' => env('GOOGLE_SECRET', ''),
],
'oschina' => [
'client_id' => env('OSCHINA_CLIENT_ID', ''),
'redirect_uri' => env('OSCHINA_CALLBACK', ''),
'client_secret' => env('OSCHINA_SECRET', ''),
],
'stackoverflow' => [
'client_id' => env('OSCHINA_CLIENT_ID', ''),
'redirect_uri' => env('OSCHINA_CALLBACK', ''),
'client_secret' => env('OSCHINA_SECRET', ''),
'client_key' => env('OSCHINA_SECRET', ''),
],
'dingtalk' => [
'client_id' => env('OSCHINA_CLIENT_ID', ''),
'redirect_uri' => env('OSCHINA_CALLBACK', ''),
'client_secret' => env('OSCHINA_SECRET', ''),
]
];
167 changes: 162 additions & 5 deletions src/Config/AuthDefaultSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ class AuthDefaultSource
public $github;
public $weibo;
public $weixin;
public $douyin;
public $qq;
public $huawei;
public $google;
public $baidu;
public $oschina;
public $stackoverflow;
public $dingtalk;

public function __construct()
{
$this->gitee = new class extends AuthSource {
$this->gitee = new class extends AuthSource {
public function authorize(): string
{
return "https://gitee.com/oauth/authorize";
Expand All @@ -36,7 +44,7 @@ public function userInfo(): string
return "https://gitee.com/api/v5/user";
}
};
$this->github = new class extends AuthSource {
$this->github = new class extends AuthSource {
public function authorize(): string
{
return "https://github.com/login/oauth/authorize";
Expand All @@ -49,10 +57,10 @@ public function accessToken(): string

public function userInfo(): string
{
return "https://api.github.com/user";
return "https://api.github.com/user/repos";
}
};
$this->weibo = new class extends AuthSource {
$this->weibo = new class extends AuthSource {
public function authorize(): string
{
return "https://api.weibo.com/oauth2/authorize";
Expand All @@ -73,7 +81,7 @@ public function userId(): string
return "https://api.weibo.com/oauth2/get_token_info?access_token=";
}
};
$this->weixin = new class extends AuthSource {
$this->weixin = new class extends AuthSource {
public function authorize(): string
{
return "https://open.weixin.qq.com/connect/qrconnect";
Expand All @@ -89,6 +97,155 @@ public function userInfo(): string
return "https://api.weixin.qq.com/sns/userinfo";
}
};
$this->douyin = new class extends AuthSource {
public function authorize(): string
{
return "https://open.douyin.com/platform/oauth/connect/";
}

public function accessToken(): string
{
return "https://open.douyin.com/oauth/access_token/";
}

public function userInfo(): string
{
return "https://open.douyin.com/oauth/userinfo/";
}
};
$this->qq = new class extends AuthSource {
public function authorize(): string
{
return "https://graph.qq.com/oauth2.0/authorize";
}

public function accessToken(): string
{
return "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code";
}

public function userInfo(): string
{
return "https://graph.qq.com/user/get_user_info";
}

public function getUid(): string
{
return "https://graph.qq.com/oauth2.0/me?access_token=";
}

public function getUnionid(): string
{
return "https://graph.qq.com/oauth2.0/me?access_token=";
}
};
$this->huawei = new class extends AuthSource {
public function authorize(): string
{
return "https://oauth-login.cloud.huawei.com/oauth2/v2/authorize";
}

public function accessToken(): string
{
return "https://oauth-login.cloud.huawei.com/oauth2/v3/token";
}

public function userInfo(): string
{
return "https://api.cloud.huawei.com/rest.php?nsp_fmt=JSON&nsp_svc=huawei.oauth2.user.getTokenInfo";
}
};
$this->google = new class extends AuthSource {
public function authorize(): string
{
return "https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline";
}

public function accessToken(): string
{
return "https://accounts.google.com/o/oauth2/token";
}

public function userInfo(): string
{
return "https://www.googleapis.com/oauth2/v1/userinfo";
}

public function scope(): string
{
return "https://www.googleapis.com/auth/userinfo.profile";
}
};
$this->baidu = new class extends AuthSource {
public function authorize(): string
{
return "http://openapi.baidu.com/oauth/2.0/authorize";
}

public function accessToken(): string
{
return "https://openapi.baidu.com/oauth/2.0/token";
}

public function userInfo(): string
{
return "https://openapi.baidu.com/rest/2.0/passport/users/getInfo";
}
};
$this->oschina = new class extends AuthSource {
public function authorize(): string
{
return "https://www.oschina.net/action/oauth2/authorize";
}

public function accessToken(): string
{
return "https://www.oschina.net/action/openapi/token";
}

public function userInfo(): string
{
return "https://www.oschina.net/action/openapi/my_information";
}
};
$this->stackoverflow = new class extends AuthSource {
public function authorize(): string
{
return "https://stackoverflow.com/oauth";
}

public function accessToken(): string
{
return "https://stackoverflow.com/oauth/access_token/json";
}

public function userInfo(): string
{
return "https://api.stackexchange.com/2.2/me";
}
};
$this->dingtalk = new class extends AuthSource {
public function authorize(): string
{
return "https://oapi.dingtalk.com/connect/qrconnect";
}

public function accessToken(): string
{
return "https://oapi.dingtalk.com/sns/gettoken";
}

public function userInfo(): string
{
return "https://oapi.dingtalk.com/sns/getuserinfo_bycode";
}

public function getPersistentCode(): string
{
return "https://oapi.dingtalk.com/sns/get_persistent_code";
}
};

}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Enums/AuthResponseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ class AuthResponseStatus extends Enum
/** @msg('Illegal state') */
const ILLEGAL_STATUS = 5009;
/** @msg('Config Error') */
const CONFIG_ERROR=5010;
const CONFIG_ERROR = 5010;
/** @msg('Config Source Error') */
const CONFIG_SOURCE_ERROR=5011;

const CONFIG_SOURCE_ERROR = 5011;
/** @msg('Get user openid eroor') * */
const GET_OPENID_ERROR = 5012;
/** @msg('Get user info eroor') * */
const GET_USERINFO_ERROR = 5013;

}
Loading