Ole*_* Sh 5 c# microsoft-graph-api
我用GraphServiceClient
当我尝试打电话时:
var currentUser = await _graphServiceClient.Me.Request().GetAsync();
Run Code Online (Sandbox Code Playgroud)
有用。
但是当我尝试打电话时:
var inbox = await _graphServiceClient.Me.Messages.Request().GetAsync();
Run Code Online (Sandbox Code Playgroud)
我收到:
ServiceException:代码:InvalidMsaTicket 消息:错误代码:“PP_E_RPS_REASON_OFFERACTIONS_INVALID”。信息: ''
为什么这样?怎么了?
添加:
当我注册新应用程序时,我从支持的帐户类型中选择了“任何组织目录中的帐户(任何 Azure AD 目录 - 多租户)和个人 Microsoft 帐户(例如 Skype、Xbox)”
结果我有:
客户秘密:
以下身份验证:
和API权限:
我的应用程序具有以下身份验证:
和相同的权限:
我的appsettings.json:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "https://spoutlookdev.azurewebsites.net",
"TenantId": "common",
"ClientId": "2505a5*************5eb",
"ClientSecret": "Upw8Q~************-UKCa2s",
"ClientCertificates": [
],
"ClientCapabilities": [ "cp1" ],
"CallbackPath": "/signin-oidc"
},
"DownstreamApi": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
//"Scopes": "mail.read mail.readbasic mail.readbasic.all mail.readwrite user.read"
"Scopes": "user.read Mail.Read Mail.ReadBasic Mail.ReadWrite email profile"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Run Code Online (Sandbox Code Playgroud)
和Program.cs:
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor()
.AddMicrosoftIdentityConsentHandler()
;
var config = builder.Configuration;
string[]? initialScopes = config.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(config.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(config.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
Run Code Online (Sandbox Code Playgroud)
注意:当它请求权限时,它仅请求基本信息(个人资料和电子邮件),但不请求阅读邮件。可以吗?
权限中的“状态”是什么意思?其中一些标记为“已授予 3MD”,另一些则标记为“已授予 3MD”。能有影响吗?
小智 -1
您能否尝试使用 Microsoft Graph Explorer 并检查 URl -https://graph.microsoft.com/v1.0/me/messages ,如果仍然无法正常工作,请告诉我们您遇到了什么错误。也请尝试与其他用户核实,其用户是否特定?
| 归档时间: |
|
| 查看次数: |
363 次 |
| 最近记录: |