我试图将OneDrive for Busines集成到Web表单应用程序中.为此,我使用此URL提供的文档https://dev.onedrive.com/auth/aad_oauth.htm 在Web表单应用程序中我有两个页面第一个是登录页面,其中有一个用于登录的按钮在按钮登录中单击我我正在使用以下代码向OneDrive for Business API发出GET请求
HttpClient client = new HttpClient();
Redirecturi = Uri.EscapeDataString(Redirecturi);
string url = string.Format("https://login.windows.net/common/oauth2/authorize?response_type=code&client_id={0}&redirect_uri={1}", ClienId, Redirecturi);
var response = client.GetAsync(url);
var json = response.Result.Content.ReadAsStringAsync();
Label2.Text = json.Result;
Run Code Online (Sandbox Code Playgroud)
当我点击登录按钮时,它将我带到micorosoft登录服务并将我发送回带有访问代码的callback.aspx页面(在azure上配置重定向URi)
我获得了访问代码在第二页上,我正在兑换访问代码并发出POST请求以获取身份验证令牌这是第二页的代码.
private string BaseUri="https://login.windows.net/common/oauth2/token";
public string Redirecturi = "http://localhost:51642/CallBack.aspx";
public string ResourcesId = "https://api.office.com/discovery/";
private string ClienId = "180c6ac4-5829-468e-.....-822405804862"; ///truncated//azure
private string ClientSecert = "G4TAQzD8d7C4...OE6m366afv8XKbTCcyXr4=";//truncated
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString[OAuthConstants.AccessToken]))
{
// There is a token available already. It should be the …Run Code Online (Sandbox Code Playgroud)