package com.moral.controller;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.moral.service.TokenService;
|
|
@RestController
|
public class TokenControllers {
|
|
@Resource
|
private TokenService tokenService;
|
|
@GetMapping("oauth/token/{type}/{username}/{password}")
|
public Map<String, Object> getAuthToken(@PathVariable("username") String username,
|
@PathVariable("password") String password, @PathVariable("type") String type, HttpServletRequest request) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
if (ObjectUtils.isEmpty(username) || ObjectUtils.isEmpty(password) || ObjectUtils.isEmpty(type)) {
|
result.put("msg", "参数输入不合法");
|
} else {
|
String url = request.getRequestURL().toString().replace(request.getRequestURI(), "") + request.getContextPath();
|
String realPath = request.getServletContext().getRealPath("/");
|
result = tokenService.getAuthToken(type, username, password, url);
|
}
|
return result;
|
}
|
|
@PostMapping("oauth/token/{refresh_token}")
|
public Map<String, Object> getAuthToken(@PathVariable("refresh_token") String refresh_token,HttpServletRequest request) {
|
Map<String, Object> result = new HashMap<String, Object>();
|
if (ObjectUtils.isEmpty(refresh_token)) {
|
result.put("msg", "参数输入不合法");
|
} else {
|
String url = request.getRequestURL().toString().replace(request.getRequestURI(), "") + request.getContextPath();
|
result = tokenService.getAuthToken(refresh_token, url);
|
}
|
return result;
|
}
|
}
|