V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ivydom
V2EX  ›  程序员

Authing 云端用户认证系统开发文档(JavaScript)

  •  
  •   ivydom · 2018-04-03 19:23:00 +08:00 · 1370 次点击
    这是一个创建于 2233 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Authing 开发文档


    Authing 是一个提供身份认证服务的产品:https://authing.cn.

    Authing 让您 7 行代码接入用户系统成为可能。

    cmd-markdown-logo

    如果您想为 Authing 贡献 SDK,请参考SDK Guide

    功能特性

    • 第三方 OAuth 配置使用
    • 依托 Web UI 的用户管理系统
    • 跨平台多终端集成能力(即将支持 Android、iOS )
    • 基于 HTTPS 和 JWT 的安全认证方式
    • 自定义邮件模版、自定义第三方邮件服务
    • Docker 微服务架构,拥有 99.9%的服务可用性
    • 基于 GraphQL 的消息通信

    开发平台

    未来我们将支持大部分主流语言,但目前我们只支持 Javascript:

    1 条回复    2018-04-03 19:23:24 +08:00
    ivydom
        1
    ivydom  
    OP
       2018-04-03 19:23:24 +08:00
    # authing-js-sdk

    ----------

    JavaScript SDK 支持 **Angular.js**, **React.js**, **Vue.js** 以及 **Node.js**.我们提供了完全一致的接口.

    ## 安装

    ----------

    #### NPM

    当构建大规模应用时,我们推荐使用```npm```进行安装, 它可以与一些模块打包工具很好地配合使用,如 ```Webpack```, ```Browserify。```

    ``` shell
    # latest stable
    $ npm install authing-js-sdk --save
    ```

    ## 开始使用

    ----------

    ##### 使用方法

    ##### ES5

    在```ES5```中我们使用 **Promise** 处理异步编程。

    ``` javascript
    var Authing = require('authing-js-sdk');

    // 对 Client ID 和 Client Secret 进行验证,获取 Access Token
    var auth = new Authing({
    clientId: 'your_client_id',
    secret: 'your_app_secret'
    });

    auth.then(function(validAuth) {

    //验证成功后返回新的 authing-js-sdk 实例(validAuth),可以将此实例挂在全局

    validAuth.login({
    email: '[email protected]',
    password: 'testpassword'
    }).then(function(user) {
    console.log(user);
    }).catch(function(error) {
    conosle.log(error);
    });

    }).catch(function(error) {
    //验证失败
    console.log(error);
    });

    ```

    [怎样获取 client ID ?]( http://docs.authing.cn/#/quick_start/howto)。


    ##### ES6+

    在```ES6+```中,我们使用 **async 函数** 和 **await 关键字** 处理异步编程。

    ``` javascript
    import Authing from 'authing-js-sdk';

    const main = async () => {

    //使用 async 时需要使用 try...catch...捕捉错误

    let auth;

    try{
    auth = await new Authing({
    clientId: 'your_client_id',
    secret: 'your_app_secret'
    });
    }catch(error) {
    console.log('Authing 验证失败:', error);
    }

    if(auth) {

    let user;

    try {
    user = await auth.login({
    email: '[email protected]',
    password: 'testpassword'
    });
    }catch(error) {
    console.log('登录失败:', error);
    }

    if(user) {
    console.log('login success');
    }else {
    console.log('login failed');
    }

    }

    }

    main();

    ```

    了解更多报错的详情,请查看[错误代码]( http://docs.authing.cn/#/quick_start/error_code)。

    获取 Client ID 和 Client Secret,请[点击这里]( http://docs.authing.cn/#/quick_start/howto)。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1903 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:38 · PVG 00:38 · LAX 09:38 · JFK 12:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.