cn.herodotus.engine.oauth2.management.controller.OAuth2DeviceController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oauth2-sdk-management Show documentation
Show all versions of oauth2-sdk-management Show documentation
Dante Cloud 基于 Spring Authorization Server 的认证核心管理模块
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君), Licensed under the AGPL License
*
* This file is part of Herodotus Engine.
*
* Herodotus Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Herodotus Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package cn.herodotus.engine.oauth2.management.controller;
import cn.herodotus.engine.assistant.definition.domain.Result;
import cn.herodotus.engine.data.core.service.WriteableService;
import cn.herodotus.engine.oauth2.management.entity.OAuth2Device;
import cn.herodotus.engine.oauth2.management.service.OAuth2DeviceService;
import cn.herodotus.engine.rest.core.controller.BaseWriteableRestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Description: OAuth2DeviceController
*
* @author : gengwei.zheng
* @date : 2023/5/15 16:58
*/
@RestController
@RequestMapping("/authorize/device")
@Tags({
@Tag(name = "OAuth2 认证服务接口"),
@Tag(name = "物联网管理接口"),
@Tag(name = "物联网设备接口")
})
public class OAuth2DeviceController extends BaseWriteableRestController {
private final OAuth2DeviceService deviceService;
public OAuth2DeviceController(OAuth2DeviceService deviceService) {
this.deviceService = deviceService;
}
@Override
public WriteableService getWriteableService() {
return deviceService;
}
@Operation(summary = "给设备分配Scope", description = "给设备分配Scope")
@Parameters({
@Parameter(name = "deviceId", required = true, description = "设备ID"),
@Parameter(name = "scopes[]", required = true, description = "Scope对象组成的数组")
})
@PutMapping
public Result authorize(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "scopes[]") String[] scopes) {
OAuth2Device device = deviceService.authorize(deviceId, scopes);
return result(device);
}
}