Microsoft Graph-API 和 Azure 移动应用
Microsoft Graph-API and Azure Mobile Apps
我有一个移动应用程序,想使用 Microsoft Graph-API 进行身份验证。
我正在使用 Microsoft.Identity.Client 命名空间。我可以通过调用
获得令牌
authResult = await App.PublicClientApp.AcquireTokenAsync(_scopes);
当我通过调用
将此令牌传递到我的移动应用程序时
azureUser = await App.MobileService.LoginWithMicrosoftAccountAsync(authResult.AccessToken);
我收到 MobileServiceInvalidOperationException“您无权查看此目录或页面”。
我已经在应用程序注册门户中注册了我的应用程序。
Registration Portal
在 Azure 中它看起来像这样:
Azure Portal
我错了什么???
亲切的问候,
马丁
Easy Auth 不支持使用从 Azure AD V2.0 颁发的访问令牌交换令牌(在本例中使用 MSAL 库)。
要使用移动客户端的客户端流程,您可以使用 OneDrive 身份验证库从终结点获取 Microsoft 帐户的令牌。
这里有一个类似的线程供您参考:
下面是适合我的代码:
public async Task TestEasyAuthAsync()
{
string acess_token = await AcquireTokenForLiveAccount();
string applicationUrl = "https://mobilefei.azurewebsites.net/";
var mobileClient = new MobileServiceClient(applicationUrl);
JObject token = new JObject();
token.Add("access_token", acess_token);
var user = await mobileClient.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, token);
Console.WriteLine($"UserID:\n{user.UserId}");
var result = await mobileClient.InvokeApiAsync(@"/.auth/me");
Console.Read();
}
public async Task<string> AcquireTokenForLiveAccount()
{
var msAuth = new MsaAuthenticationProvider("57336bd5-a80f-4b48-a29a-07fdea6ef91e", "https://login.microsoftonline.com/common/oauth2/nativeclient", new string[] { "wl.signin", "wl.offline_access" });
await msAuth.AuthenticateUserAsync();
return msAuth.CurrentAccountSession.AccessToken;
}
我有一个移动应用程序,想使用 Microsoft Graph-API 进行身份验证。 我正在使用 Microsoft.Identity.Client 命名空间。我可以通过调用
获得令牌authResult = await App.PublicClientApp.AcquireTokenAsync(_scopes);
当我通过调用
将此令牌传递到我的移动应用程序时azureUser = await App.MobileService.LoginWithMicrosoftAccountAsync(authResult.AccessToken);
我收到 MobileServiceInvalidOperationException“您无权查看此目录或页面”。
我已经在应用程序注册门户中注册了我的应用程序。 Registration Portal
在 Azure 中它看起来像这样: Azure Portal
我错了什么???
亲切的问候,
马丁
Easy Auth 不支持使用从 Azure AD V2.0 颁发的访问令牌交换令牌(在本例中使用 MSAL 库)。
要使用移动客户端的客户端流程,您可以使用 OneDrive 身份验证库从终结点获取 Microsoft 帐户的令牌。 这里有一个类似的线程供您参考:
下面是适合我的代码:
public async Task TestEasyAuthAsync()
{
string acess_token = await AcquireTokenForLiveAccount();
string applicationUrl = "https://mobilefei.azurewebsites.net/";
var mobileClient = new MobileServiceClient(applicationUrl);
JObject token = new JObject();
token.Add("access_token", acess_token);
var user = await mobileClient.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, token);
Console.WriteLine($"UserID:\n{user.UserId}");
var result = await mobileClient.InvokeApiAsync(@"/.auth/me");
Console.Read();
}
public async Task<string> AcquireTokenForLiveAccount()
{
var msAuth = new MsaAuthenticationProvider("57336bd5-a80f-4b48-a29a-07fdea6ef91e", "https://login.microsoftonline.com/common/oauth2/nativeclient", new string[] { "wl.signin", "wl.offline_access" });
await msAuth.AuthenticateUserAsync();
return msAuth.CurrentAccountSession.AccessToken;
}