用户
web指纹
登录
oauthapp.signInWithWebIdentity
如果账号不存在就自动注册,并返回用户信息。
提示
该方法通过使用 FingerprintJS2 库生成当前设备的 web 指纹,并通过与 OAuthApp 后台服务器进行匹配来自动完成用户的注册或登录。
如果用户之前已经在该应用程序中注册过,此方法将自动登录用户并返回用户数据。该方法返回一个 promise 对象,该对象在用户登录成功时解析为用户数据。如果发生错误,则返回拒绝状态。
演示 教程
UnionID
UnionID可以是任意平台的用户ID,unionID + platform 必须唯一。
登录
oauthapp.unionIDSignIn
提示
该方法用于用户已经在第三方平台(例如微信)进行了登录,并且已经获得了该平台的 unionId,此时应用程序需要将该 unionId 提交给 OAuthApp 服务器进行处理。OAuthApp 服务器会检查是否存在与该 unionId 相关联的账户,并返回生成的 access_token,应用程序通过该 access_token 访问 OAuthApp API。
演示 教程
注册
oauthapp.unionIDSignUp
提示
该方法将会向 OAuthApp 后台服务器发送注册请求。如果请求成功,服务器将返回一个包含 access_token 的 JSON 对象,可以用于后续的 API 请求。如果注册失败,将会返回相应的错误信息。
| /**
* data 属性:
{
"unionID": "string",
"platform": "string",
"pwd": "yc6EJ}v~tTzl!J@NQ@9Rl|}JX",
"nickName": "string",
"avatar": "string",
"data": "string",
"email": "user@example.com",
"emailCode": "",
"phone": "",
"phoneCode": ""
}
*/
oauthapp.unionIDSignUp(data).then(function(res){
console.log(res);
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UnionID注册</title>
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></ script>
</head>
<body>
<div>
<h3>UnionID注册</h3>
<p>unionId:<input type="text" id="unionId" /></p>
<p>platform:<input type="text" id="platform" /></p>
<p>password:<input type="text" id="password" /></p>
<p>nickName:<input type="text" id="nickName" /></p>
<p>avatar:<input type="text" id="avatar" /></p>
<p>data:<input type="text" id="data" /></p>
<p>email:<input type="text" id="email" /></p>
<p>emailCode:<input type="text" id="emailCode" /></p>
<p>phone:<input type="text" id="phone" /></p>
<p>phoneCode:<input type="text" id="phoneCode" /></p>
<button type="button" id="actionButton">提交</button>
</div>
<div id="result"></div>
<script>
oauthapp.ready().then(function () {
$('#actionButton').click(function () {
var data = {
"unionID": $('#unionId').val() || oauthapp.settings.fingerIdentity,
"platform": $('#platform').val() || 'web',
"pwd": $('#password').val() || '123456',
"nickName":$('#nickName').val() || '',
"avatar": $('#avatar').val() || oauthapp.app.info.logo,
"data": $('#data').val() || '',
"email": $('#email').val() || '',
"emailCode": $('#emailCode').val() || '',
"phone": $('#phone').val() || '',
"phoneCode": $('#phoneCode').val() || ''
};
oauthapp.unionIDSignUp(data).then(function (res) {
$('#result').text(JSON.stringify(res));
});
})
});
</script>
</body>
</html>
|
参数 |
说明 |
|
unionId |
第三方平台的用户ID |
oauthapp.settings.fingerIdentity / 自定义 |
platform |
第三方平台标识字符串 |
web、weibo、wexin、qq、dingtalk / 自定义 |
pwd |
密码,可空 |
默认为:123456 |
nickname |
昵称,可空 |
|
avatar |
头像,可空 |
|
data |
自定义数据,可空 |
|
phone |
手机号,可空 |
如果应用配置了验证手机,则必填 |
phoneCode |
手机验证码,可空 |
如果应用配置了验证手机,则必填 |
email |
邮箱,可空 |
如果应用配置了验证邮箱,则必填 |
emailCode |
邮箱已验证,可空 |
如果应用配置了验证邮箱,则必填 |
演示 教程
账号密码
登录
oauthapp.accountSignIn
提示
使用账号密码登录。它向OAuthApp服务器发送请求,使用传递的用户名和密码进行身份验证,如果验证成功,则返回包含 access_token 和其他用户信息的响应对象,以便后续的 API 调用。
演示 教程
注册
oauthapp.accountSignUp
提示
该方法会向后台服务器发送请求,在服务器上创建一个新的用户账户,账户创建成功后,会直接返回access_token。
| /**
* data 属性:
{
"userName": "uM@J5",
"pwd": "6E7U3CESUFTCQF4SfDcN|{CO3Ea~3WG",
"nickName": "string",
"avatar": "string",
"data": "string",
"email": "user@example.com",
"emailCode": "",
"phone": "",
"phoneCode": ""
}
*/
oauthapp.accountSignUp(data).then(function(res){
console.log(res);
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>accountSignUp</title>
<!-- data-appid 属性替换为你的 OAuthApp 应用的 ID -->
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></script>
</head>
<body>
<div>
<label>userName</label>
<input type="text" id="userName" />
<label>password</label>
<input type="text" id="password" />
<label>avatar</label>
<input type="text" id="avatar" />
<label>nickName</label>
<input type="text" id="nickName" />
<label>platform</label>
<input type="text" id="platform" />
<button type="button" id="signUpButton">注册</button>
</div>
<p>结果</p>
<div id="result"></div>
<script>
oauthapp.ready().then(function () {
document.getElementById('signUpButton').onclick = function () {
var userName = $('#userName').val() || oauthapp.settings.fingerIdentity;
var password = $('#password').val() || '123456';
var avatar = $('#avatar').val() || oauthapp.app.info.logo;
var nickName = $('#nickName').val() || userName;
var platform = $('#platform').val() || 'web';
oauthapp.accountSignUp(userName, password, avatar, nickName, platform).then(function (res) {
$('#result').text(JSON.stringify(res));
});
}
});
</script>
</body>
</html>
|
参数 |
说明 |
|
userName |
登录账号 |
|
pwd |
登陆密码 |
|
nickName |
昵称,可空 |
|
avatar |
头像,可空 |
|
data |
自定义数据,可空 |
|
phone |
手机号,可空 |
如果应用配置了验证手机,则必填 |
phoneCode |
手机验证码,可空 |
如果应用配置了验证手机,则必填 |
email |
邮箱,可空 |
如果应用配置了验证邮箱,则必填 |
emailCode |
邮箱已验证,可空 |
如果应用配置了验证邮箱,则必填 |
演示 教程
手机号
注册
oauthapp.phoneSignUp
| /**
* data 参数如下:
{
"phone": "",
"phoneCode": "",
"pwd": "hXeqUI3$gUKV",
"email": "user@example.com",
"emailCode": "",
"nickName": "string",
"avatar": "string",
"data": "string"
}
*/
oauthapp.phoneSignUp(data).then(function(res){
console.log(res);
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>手机号注册</title>
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></ script>
</head>
<body>
<div>
<h3>手机号注册</h3>
<p>phone:<input type="text" id="phone" /></p>
<p>phoneCode:<input type="text" id="phoneCode" /></p>
<p>password:<input type="text" id="password" /></p>
<p>email:<input type="text" id="email" /></p>
<p>emailCode:<input type="text" id="emailCode" /></p>
<p>nickName:<input type="text" id="nickName" /></p>
<p>avatar:<input type="text" id="avatar" /></p>
<p>data:<input type="text" id="data" /></p>
<button type="button" id="actionButton">提交</button>
</div>
<div id="result"></div>
<script>
oauthapp.ready().then(function () {
$('#actionButton').click(function () {
var data = {
"phone": $('#phone').val() || '',
"phoneCode": $('#phoneCode').val() || '',
"pwd": $('#password').val() || '123456',
"email": $('#email').val() || '',
"emailCode": $('#emailCode').val() || '',
"nickName": $('#nickName').val() || '',
"avatar": $('#avatar').val() || oauthapp.app.info.logo,
"data": $('#data').val() || ''
};
oauthapp.phoneSignUp(data).then(function (res) {
$('#result').text(JSON.stringify(res));
});
})
});
</script>
</body>
</html>
|
参数 |
说明 |
|
phone |
手机号,必填 |
|
phoneCode |
手机验证码,必填 |
调用发送手机验证码方法获取 |
pwd |
密码,可空 |
默认为:123456 |
email |
邮箱,可空 |
如果应用配置了验证邮箱,则必填 |
emailCode |
邮箱已验证,可空 |
如果应用配置了验证邮箱,则必填 |
nickname |
昵称,可空 |
|
avatar |
头像,可空 |
|
data |
自定义数据,可空 |
|
演示
登录
oauthapp.phoneSignIn
演示
找回密码
oauthapp.resetPwd
演示
发送验证码
oauthapp.sendSMSCode
演示
邮箱账号
注册
oauthapp.emailSignUp
| /**
* data参数如下:
* {
"email": "user@example.com",
"pwd": "897V5rFabJ3&!#",
"emailCode": "16509",
"phone": "49735952361",
"phoneCode": "50840290",
"nickName": "string",
"avatar": "string",
"data": "string"
}
*/
oauthapp.emailSignUp(data).then(function(res){
console.log(res);
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>使用邮箱注册</title>
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></ script>
</head>
<body>
<div>
<h3>使用邮箱注册</h3>
<p>email:<input type="text" id="email" /></p>
<p>emailCode:<input type="text" id="emailCode" /></p>
<p>phone:<input type="text" id="phone" /></p>
<p>phoneCode:<input type="text" id="phoneCode" /></p>
<p>password:<input type="text" id="password" /></p>
<p>nickName:<input type="text" id="nickName" /></p>
<p>avatar:<input type="text" id="avatar" /></p>
<p>data:<input type="text" id="data" /></p>
<button type="button" id="actionButton">提交</button>
</div>
<div id="result"></div>
<script>
oauthapp.ready().then(function () {
$('#actionButton').click(function () {
var data = {
"email": $('#email').val() || '',
"emailCode": $('#emailCode').val() || '',
"phone": $('#phone').val() || '',
"phoneCode": $('#phoneCode').val() || '',
"pwd": $('#password').val() || '123456',
"nickName": $('#nickName').val() || '',
"avatar": $('#avatar').val() || oauthapp.app.info.logo,
"data": $('#data').val() || ''
};
oauthapp.emailSignUp(data).then(function (res) {
$('#result').text(JSON.stringify(res));
}).catch(err=>{
$('#result').text(err.responseText);
});
})
});
</script>
</body>
</html>
|
参数 |
说明 |
|
email |
邮箱,必填 |
|
emailCode |
邮箱已验证,必填 |
调用发送邮箱验证码方法获取 |
pwd |
密码,可空 |
默认为:123456 |
nickname |
昵称,可空 |
|
avatar |
头像,可空 |
|
data |
自定义数据,可空 |
|
phone |
手机号,可空 |
如果应用配置了验证手机,则必填 |
phoneCode |
手机验证码,可空 |
如果应用配置了验证手机,则必填 |
演示
登录
oauthapp.emailSignIn
演示
找回密码
oauthapp.resetPwd
演示
发送验证码
oauthapp.sendEmailCode
演示
微信小程序
扫码登录
oauthapp.minipSignInQRCode
使用微信小程序扫码登录
提示
生成一个带有登录授权的二维码,并在HTML页面展示该二维码。
用户使用微信扫描该二维码后,会跳转到小程序进行授权操作。
授权成功后,HTML页面通过 oauthapp.minipSignInResult(signInKey) 方法查询用户信息和access_token等数据,然后进行相应的处理。
该方法返回2个参数,signInKey(用于查询登录状态)、qrcode(用img标签展示给用户扫码)。
需要先使用发布工具,在应用>>应用配置>>微信小程序 菜单下,配置 微信小程序ClientID、微信小程序ClientSecret。
演示 教程
扫码结果查询
oauthapp.minipSignInResult
用于获取微信小程序授权登录的结果
提示
其中signInKey为授权登录时生成的签名密钥。该方法会向服务器发送请求,查询微信小程序授权登录的结果,并返回一个包含登录状态、用户信息和访问令牌的对象。如果授权登录尚未完成,则返回一个空对象。
演示 教程
确认扫码与注册
以下操作需要在小程序端进行操作
钉钉
登录
oauthapp.dingtalkSignIn
使用钉钉自动注册+登录。
提示
该方法用于用户已经在钉钉平台进行了登录,并且已经获得了auth code,此时应用程序需要将该 code 提交给 OAuthApp 服务器进行处理。OAuthApp 服务器会检查是否存在与该 code 相关联的账户,并返回生成的 access_token,应用程序通过该 access_token 访问 OAuthApp API。
钉钉应用需申请如下权限:
- 成员信息读权限(qyapi_get_member)
- 个人手机号信息(Contact.User.mobile)
- 邮箱等个人信息(fieldEmail)
- 钉钉应用需配置IP白名单、PC/移动端的网页地址
发布工具需要,在应用>>应用配置>>顶顶应用 菜单下,配置:
- 应用ClientID
- 应用ClientSecret
- 企业ID。
演示 教程
access_token 登录
oauthapp.accesstokenSignIn
直接使用access_token登录并获取用户资料。
提示
使用传入的 Access Token 直接在后台服务器上进行验证和登录,并返回相应的用户信息。具体功能包括:
演示 教程
OAuthApp统一登录
使用统一的UI登录,用户登录后会回传accesstoken到回调地址。 可使用配置工具生成登录链接。
提示
用户点击单点登录链接,跳转到OAuthApp的授权页面。
用户在授权页面上输入用户账号和密码,授权页面验证身份后会展示需要授权的权限列表。
当用户授权成功后,单点登录会将访问令牌(access token)重定向到预设的回调地址(redirect_uri)上,并将其作为参数传递给回调地址。
在回调地址中,可以通过解析 URL 参数来获取访问令牌,然后调用 access_token 登录 登录或进行后续操作。
演示 教程
获取用户资料
oauthapp.profile
用于获取当前登录用户的个人信息,包括用户 ID、昵称、头像等信息。
演示 教程
更新用户资料
oauthapp.profilePut
必须登录以后才能更新用户信息,可更新头像、昵称、自定义json数据3个字段。
演示 教程
开放认证
申请授权码
oauthapp.oauthGrantCode
| /**
* scheme 固定为:app
* data 参数如下:
* {
"redirect_uri": "string",
"grant_type": "email",
"scopes": "string",
"userName": "string",
"password": "string",
"unionId": "string",
"platform": "string",
"expireInDays": 99
}
*/
oauthapp.oauthGrantCode(scheme,data).then(function(res){
console.log(res);
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>申请授权码</title>
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></ script>
</head>
<body>
<div>
<h3>申请授权码</h3>
<p>redirect_uri:<input type="text" id="redirect_uri" /></p>
<p>expireInDays:<input type="number" min="1" max="99" value="1" id="expireInDays" /></p>
<p>scopes:<input type="text" id="scopes" /></p>
<p><select id="grant_type" onchange="toggleIdentityDiv(this.value)">
<option>email</option>
<option>phone</option>
<option>unionid</option>
<option>account</option>
</select></p>
<div id="identity1">
<p>userName:<input type="text" id="userName" /></p>
<p>password:<input type="text" id="password" /></p>
</div>
<div id="identity2" style="display: none;">
<p>unionId:<input type="text" id="unionId" /></p>
<p>platform:<input type="text" id="platform" /></p>
</div>
<button type="button" id="actionButton">提交</button>
</div>
<div id="result"></div>
<script>
function toggleIdentityDiv(val) {
console.log(val)
if (val == 'unionid') {
$('#identity1').hide();
$('#identity2').show();
}
else {
$('#identity2').hide();
$('#identity1').show();
}
}
oauthapp.ready().then(function () {
$('#actionButton').click(function () {
var data = {
"redirect_uri": $('#redirect_uri').val(),
"grant_type": $('#grant_type').val(),
"scopes": $('#scopes').val(),
"userName": $('#userName').val(),
"password": $('#password').val(),
"unionId": $('#unionId').val(),
"platform": $('#platform').val(),
"expireInDays": $('#expireInDays').val()
};
oauthapp.oauthGrantCode('app', data).then(function (res) {
$('#result').text(JSON.stringify(res));
}).catch(err => {
$('#result').text(err.responseText);
});
})
});
</script>
</body>
</html>
|
参数 |
说明 |
|
scheme |
身份验证协议 |
固定填:app |
data参数如下 |
|
|
redirect_uri |
返回地址,必填 |
默认无限制,也可在【安全-开放认证网址白名单】配置 |
grant_type |
授权类型,必填 |
可选:email、phone、unionid、account |
scopes |
自定义授权范围,必填 |
用英文空格分隔 |
userName |
用户名 |
授权类型为:email/phone/account必填 |
password |
登录密码 |
授权类型为:email/phone/account必填 |
unionId |
unionId |
授权类型为:unionid必填 |
platform |
平台 |
授权类型为:unionid必填 |
expireInDays |
授权有效期(天) |
默认为1,取值范围:1~99 |
演示
获取access_token
oauthapp.oauthAuthorize
演示
授权记录
oauthapp.oauthConsents
演示
删除授权记录
oauthapp.oauthDeleteConsent
演示
积分记录
oauthapp.pointLogs
提示
获取当前登录用户的积分变更记录。
| /**
* 积分记录
* @params type 分类 | 0:全部,1:充值,2:消耗
* @params skip 跳过条数
* @params take 拉取条数
*/
oauthapp.pointLogs(type,skip,take).then(function(res){
console.log(res);
/**
{
"code": 200,
"data": {
"total": 2,
"data": [
{
"id": 2,
"userID": 84,
"used": 10000,
"remark": "",
"createDate": "2023-06-16 15:35:06"
},
{
"id": 1,
"userID": 84,
"used": 10000,
"remark": "",
"createDate": "2023-06-16 15:23:50"
}
]
},
"err": ""
}
*
*/
});
|
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>order</title>
<!-- data-appid 属性替换为你的 OAuthApp 应用的 ID -->
<script id="appcore" src="https://www.oauthapp.com/lib/sdk/oauthapp.1.9.8.js" data-appid="2"></script>
</head>
<body>
<select id="type">
<option value="0">全部</option>
<option value="1">充值</option>
<option value="2">消耗</option>
</select>
<input type="text" id="skip" value="0" />
<input type="text" id="take" value="10" />
<button type="button" id="actionButton">查询</button>
<p>结果</p>
<div id="result"></div>
<script>
oauthapp.allReady().then(function () {
document.getElementById('actionButton').onclick = function () {
var type = $('#type').val() || 0;
var skip = $('#skip').val() || 0;
var take = $('#take').val() || 10;
oauthapp.pointLogs(type, skip, take).then(function (res) {
$('#result').text(JSON.stringify(res));
});
};
});
</script>
</body>
</html>
|
参数 |
说明 |
|
type |
分类 |
0:全部,1:充值,2:消耗 |
skip |
可选,指定要拉取的数据条数。 |
0 |
take |
可选,指定要跳过的数据条数。 |
10 |
演示 教程
最后更新:
July 26, 2023