您必须使用
grant_type=password并调用
oauth2/token端点。这是用于身份验证的C#版本:
private async Task<string> GetAccessToken(){ string tokenEndpointUri = Authority + "oauth2/token"; var content = new FormUrlEnpredContent(new [] { new KeyValuePair<string, string>("grant_type", "password"), new KeyValuePair<string, string>("username", Username), new KeyValuePair<string, string>("password", Password), new KeyValuePair<string, string>("client_id", ClientId), new KeyValuePair<string, string>("client_secret", ClientSecret), new KeyValuePair<string, string>("resource", PowerBiResourceUri) } ); using (var client = new HttpClient()) { HttpResponseMessage res = await client.PostAsync(tokenEndpointUri, content); string json = await res.Content.ReadAsStringAsync(); AzureAdTokenResponse tokenRes = JsonConvert.DeserializeObject<AzureAdTokenResponse>(json); return tokenRes.AccessToken; }}在请求中,您必须指定:
- 用户名
- 密码
- 客户编号
- 客户机密
- 资源URI



