瀏覽代碼

v2.1 test

lijian 1 年之前
父節點
當前提交
90c177b77a
共有 2 個文件被更改,包括 20 次插入1 次删除
  1. 18 1
      services/httpaccess/actions.go
  2. 2 0
      services/httpaccess/router.go

+ 18 - 1
services/httpaccess/actions.go

@@ -51,6 +51,16 @@ type DeviceAuthArgs struct {
 	Protocol     string `json:"protocol" binding:"required"`
 }
 
+type AccessAuthArgs struct {
+	UserName string `json:"username"`
+	Password string `json:"password"`
+}
+
+type AccessAuthResp struct {
+	Result      string `json:"result"`       // 可选 "allow" | "deny" | "ignore"
+	IsSuperuser bool   `json:"is_superuser"` // false
+}
+
 // RegisterDevice 设备激活
 func RegisterDevice(args DeviceRegisterArgs, r render.Render) {
 	server.Log.Printf("ACTION RegisterDevice, args:: %v ", args)
@@ -80,9 +90,16 @@ func RegisterDevice(args DeviceRegisterArgs, r render.Render) {
 	return
 }
 
+// DeviceAccessAuth emqx 设备接入认证
+func DeviceAccessAuth(args AccessAuthArgs, r render.Render) {
+	server.Log.Printf("ACTION DeviceAccessAuth, args:: %v", args)
+	result := AccessAuthResp{}
+	result.Result = "allow"
+	r.JSON(http.StatusOK, result)
+}
+
 // AuthDevice device auth
 func AuthDevice(args DeviceAuthArgs, r render.Render) {
-	server.Log.Printf("ACTION AuthDevice, args:: %v", args)
 	device := &models.Device{}
 
 	span, ctx := opentracing.StartSpanFromContext(context.Background(), "AuthDevice")

+ 2 - 0
services/httpaccess/router.go

@@ -13,4 +13,6 @@ func route(m *martini.ClassicMartini) {
 	// auth device
 	m.Post("/v1/devices/authentication", binding.Json(DeviceAuthArgs{}), AuthDevice)
 
+	m.Post("/v1/external/auth", binding.Json(AccessAuthArgs{}), DeviceAccessAuth)
+
 }