如何登录 Microsoft Azure 门户并获取授权码?

How to login into Microsoft Azure Portal and Get Auth Code?

发送GET请求后获取网站发送的所有信息的最佳方式是什么。我的主要问题是我无法使用代码登录 Microsoft 帐户。 我写了一个获取所有参数的代码:-

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class Requests {
public static void main(String[] args) throws IOException {

    URL url = new URL("Microsoft Portal URL");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setInstanceFollowRedirects(false);
    httpCon.setDoOutput(true);
    httpCon.setRequestMethod("GET");
    OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
    System.out.println("Response Code " + httpCon.getResponseCode());
    System.out.println("Response Status " + httpCon.getResponseMessage());
    System.out.println("Header Fields " + httpCon.getHeaderFields());
    System.out.println("Sent URL " + httpCon.getURL());
    out.close();
}
}

我得到的结果如下:

Response Code 200 
Response Status OK 
Header Fields {null=[HTTP/1.1 200 OK], client-request-id=[9031e090-ea92-4581-b8d1-5b1c66076b50],
Content-Length=[7796], Expires=[-1],
Set-Cookie=[stsservicecookie=ests; path=/; secure; HttpOnly,
x-ms-gateway-slice=productiona; path=/; secure; HttpOnly,
flight-uxoptin=true; path=/; secure; HttpOnly],
x-ms-gateway-service-instanceid=[ESTSFE_IN_217],
X-Powered-By=[ASP.NET], Server=[Microsoft-IIS/8.5],
Cache-Control=[no-cache, no-store], Pragma=[no-cache],
X-Content-Type-Options=[nosniff],
Strict-Transport-Security=[max-age=31536000; includeSubDomains],
x-ms-request-id=[b822c62e-2aea-45b2-93c9-f1dc67576644],
Date=[Wed, 16 Mar 2016 08:41:08 GMT], P3P=[CP="DSP CUR OTPi IND OTRi ONL FIN"],
Content-Type=[text/html; charset=utf-8]

我需要重定向 URI,它只有在我登录到 Microsoft 帐户时才可用。所以我需要使用一些代码登录网站。

---->>>>我想做的是: 以这种格式发送 Get 请求后: 获取“https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}”

它返回一个名为 code 的参数(如果我使用的是 Rest Client 应用程序)。要获取此代码,用户必须登录到 Azure 门户。

我的问题是,当我使用 java 代码执行所有这些操作时,我没有收到此代码。问题是我无法使用 java 代码登录。帮我解决这个问题。

在 Azure 上,有三组 REST API 需要进行身份验证,包括资源管理 API、服务管理 API 和其他特定的 API,如 Azure 存储或服务总线等。

  1. 要使用资源管理 API,您需要对 Azure 资源管理器请求进行身份验证,请参阅 Authenticating Azure Resource Manager requests. And there are some samples in Java you can refer to on GitHub https://github.com/Azure/azure-sdk-for-java/tree/master/azure-mgmt-samples

  2. 要使用服务管理 API,您需要对服务管理请求进行身份验证,请参阅 Authenticating Service Management Requests. There is an offical blog 显示的如何开始 Java。

  3. 要使用某些特定的 API,您需要构建一个 Shared Access Signature 令牌来委托访问。比如Delegating Access with a Shared Access Signature for Azure Storage Service REST, you can see the Service SAS Examples知道怎么构造。