Oauth 2.0 授权代码是授予资源访问权限所必需的吗?
我正在开发一个Spring Boot web应用程序,它需要从第三方web应用程序访问资源。我试图理解Oauth2的工作原理。第三方web应用程序使用Oauth2授予客户端资源访问权限。来自第三方web应用程序的文档说,要以下面提到的格式发送带有请求参数的帖子 用户名=&password=&client\u id=&client\u secret=&grant\u type=密码&hcode= hcode值根据文档固定。 我能够编写一个java代码,成功地获取我的访问令牌(感谢谷歌搜索!)。 下面是我的问题Oauth 2.0 授权代码是授予资源访问权限所必需的吗?,oauth-2.0,spring-security-oauth2,Oauth 2.0,Spring Security Oauth2,我正在开发一个Spring Boot web应用程序,它需要从第三方web应用程序访问资源。我试图理解Oauth2的工作原理。第三方web应用程序使用Oauth2授予客户端资源访问权限。来自第三方web应用程序的文档说,要以下面提到的格式发送带有请求参数的帖子 用户名=&password=&client\u id=&client\u secret=&grant\u type=密码&hcode= hcode值根据文档固定。 我能够编写一个java代码,成功地获取我的访问令牌(感谢谷歌搜索!)。 下
1这里使用的是什么类型的补助金 资源所有者密码凭据(ROPC)。请检查此项 这是授权码吗?我在这里没有看到授权码
否。谢谢您的回复。参数中有hcode,它是与资源相关的代码(本例中为诊所代码)。为什么在访问令牌获取阶段会询问此问题?获取令牌后,我将检索患者详细信息。我有点理解为什么在参数中发送clientID、clientSecret、userID和userPassword。我不清楚为什么发送grantType和hcode。有多种授予类型(隐式、授权代码、客户端凭据等以及您的案例中的ROPC)在OAuth中可用。因此,您需要指定正在使用的授权类型,以便资源服务器可以启动该流。hcode不是标准OAuth参数,可能是特定于临床代码的参数。
String content = "-----";
BufferedReader reader = null;
HttpsURLConnection connection = null;
String returnValue = "";
URL url = new URL(CredentialDto.getTockenurl());
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " +
CredentialDto.getAuthentication());
connection.setRequestProperty("Content-Type", "application/x-www-form-
urlencoded");
connection.setRequestProperty("Accept", "application/json");
PrintStream os = new PrintStream(connection.getOutputStream());
os.print(content);
os.close();
reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String line = null;
StringWriter out = new StringWriter(connection.getContentLength() > 0 ?
connection.getContentLength() : 2048);
while((line = reader.readLine()) != null) {
out.append(line);
}
accessToken = out.toString();
Matcher matcher = PAT.matcher(retuenValue); if(matcher.matches() &&
matcher.groupCount() > 0) {
accessToken = matcher.group(1);
}