New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cloudbase/oauth

Package Overview
Dependencies
Maintainers
17
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudbase/oauth - npm Package Compare versions

Comparing version 0.0.5-alpha.0 to 0.1.1-alpha

app/index.d.ts

62

package.json
{
"name": "@cloudbase/oauth",
"version": "0.0.5-alpha.0",
"description": "cloudbase javascript sdk auth componets",
"main": "./dist/index.js",
"module": "dist/esm/index.js",
"publishConfig": {
"access": "public"
},
"scripts": {
"eslint": "eslint \"{src,__tests__}/**/*.ts\"",
"eslint:fix": "eslint --fix \"{src,__tests__}/**/*.ts\"",
"clean": "rimraf dist",
"compile": "tsc",
"build": "yarn clean && yarn compile"
},
"license": "MIT",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"eslint": "^6.8.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"typescript": "^3.8.3"
},
"dependencies": {
"@cloudbase/app": "^1.5.3-alpha.0",
"@cloudbase/types": "^1.2.3-alpha.0",
"@cloudbase/utilities": "^1.4.3-alpha.0"
},
"gitHead": "ab6b1fad47cbb9865aeb2415a1229733641a9fb2"
"name": "@cloudbase/oauth",
"version": "0.1.1-alpha",
"description": "auth apis for cloudbase",
"author": "xbase",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"typesVersions": {
">=4.1": {
"*": [
"ts4.1/*"
]
}
},
"license": "MIT",
"scripts": {
"eslint": "eslint \"{src,__tests__}/**/*.ts\"",
"eslint:fix": "eslint --fix \"{src,__tests__}/**/*.ts\"",
"clean": "rm -rf dist",
"compile": "tsc",
"build": "yarn clean && yarn compile && cp package.json dist/ && cp *.md dist/"
},
"engines": {
"node": "^12.14.1 || >=14.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"eslint": "^7.32.0"
}
}

@@ -1,2 +0,2 @@

# Oauth
# xbase-sdk

@@ -16,7 +16,139 @@ 提供 oauth2 的登录相关功能。

```typescript
const authOptions = {
apiOrigin: '服务域名',
clientId: '客户端ID',
import {initializeApp} from '@clodbasesdk/oauth/app';
import {getAuth} from '@clodbasesdk/oauth/auth';
export const config = {
env: 'env-4gh5dh6nf62145a9'
};
const auth = new Auth(authOptions);
const app = initializeApp(config)
const auth = getAuth(app)
// 调用API
const loginState = await auth.hasLoginState()
```
### 账号登录
```typescript
auth.signIn({
username: 'test',
password: 'test',
});
```
### 手机验证码登录/注册
```typescript
const phoneNumber = '10012341234';
// 短信验证码
const verificationCode = '******';
const verification = await auth.getVerification({
phone_number: '+86 ' + phoneNumber,
target: 'ANY',
});
let verifyResult = await auth.verify({
verification_code: verificationCode,
verification_id: verification ? verification.verification_id : '',
});
let isUser = verification ? verification.is_user : false;
let result;
if (isUser) {
result = await auth.signIn({
username: '+86 ' + phoneNumber,
verification_code: verificationCode,
verification_token: verifyResult.verification_token,
});
} else {
result = await auth.signUp({
phone_number: '+86 ' + phoneNumber,
password: '*******',
verification_code: verificationCode,
verification_token: verifyResult.verification_token,
local: 'zh-cn',
name: '100****1234',
});
}
```
### 错误处理
```typescript
try {
await auth.verify({
verification_code: verificationCode,
verification_id: verification ? verification.verification_id : '',
});
} catch (error) {
if (error && error.error_uri === '/v1/auth/verification/verify') {
switch (error.error) {
case 'not_found': {
result = i18n.translate('error', 'User Not Found');
break;
}
case 'invalid_password': {
if (error.details !== undefined && error.details.length > 0) {
result =
i18n.translate('error', 'Certification failed, you still have') +
error.details[0].limit_remaining +
i18n.translate('error', 'chances. You can also') +
'' +
i18n.translate('error', 'Reset Login Password') +
'</a>';
} else {
result = i18n.translate('error', 'Password does not match');
}
break;
}
case 'user_pending': {
result = i18n.translate('error', 'The account is not activated');
break;
}
case 'user_blocked': {
result = i18n.translate('error', 'Account has been disabled');
break;
}
case 'invalid_status': {
if (error.details !== undefined && error.details.length > 0) {
let s = error.details[0].retry_delay;
s = s.substring(0, s.length - 1);
s = parseInt(s);
result =
i18n.translate(
'error',
'The password input error has reached the upper limit and the account will be locked ',
) +
(s < 3600
? s / 60 + i18n.translate('error', 'minute')
: s / 3600 + i18n.translate('error', 'hour'));
} else {
result = i18n.translate(
'error',
'Account has been temporarily locked',
);
}
break;
}
case 'invalid_two_factor': {
result = i18n.translate(
'error',
'Secondary authentication code does not match or has expired',
);
break;
}
case 'invalid_two_factor_recovery': {
result = i18n.translate(
'error',
'Recovery code does not match or has expired',
);
break;
}
default: {
result = i18n.translate('error', 'unknown');
break;
}
}
}
}
```
## [更新日志](./CHANGELOG.md)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc