Skip to content

外站授权登录

业务介绍

  • 您可以在您的系统中,通过JWT认证的方式,授权登录到企培站点的首页

功能接口

GET /login/external

权限

请求参数

字段类型必选描述示例
tokenstringJWT加密生成的tokenxxxxx.xxxxxx.xxxxx
gotostring经过urlEncode之后的网校路由%2Fcourse%2F1

注意

  1. goto参数从网校版本 25.1.4开始支持
  2. goto参数只接受GET获取的页面路由,传入其他类型的页面路由可能会导致跳转错误
  3. goto参数必须经过urlEncode,否则会导致授权接口报错
  4. goto参数只接受不带域名的网校内部路由(网校域名后面的路径路由)并且路由由 /开始,如果网校不包含该路由或者不是由 /开始,则参数校验无法通过

例如网校存在页面: https://example.com/course/1

则以下路由经过urlEncode之后是合法参数: /course/1 /course/1?a=b&c=d

以下路由是不合法的: https://example.com/course/1 course/1 /course/1/XXX

响应

  • 如设置了 goto参数,则跳转至该页面;否则跳转至企培站点首页

JWT Token生成

PHP
<?php
use Firebase\JWT\JWT;

$appKey = 'your-app-key';         // 替换成你的appKey
$secretKey = 'your-secret-key';  // 替换成你的secretKey
$options = ['identifyValue' => '13366669999','identifyType' => 'mobile'];

$token = JWT::encode($options, $secretKey, 'HS256', $appKey);
Java
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

String secretKey = "your-secret-key";  // 替换成你的secretKey
String appKey = "your-app-key";         // 替换成你的appKey
String identifyValue = "13366669999";
String identifyType = "mobile";

String token = JWT.create()
      .withKeyId(appKey)
      .withClaim("identifyType", identifyType)
      .withClaim("identifyValue", identifyValue)
      .sign(Algorithm.HMAC256(secretKey));

请求参数

字段类型必选描述示例
secretKey appKeystring参见:站点域名/admin/system/api/setting
identifyTypestring用户类型 username、email、mobile 三选一mobile
identifyValuestring所选类型对应的值13366669999