Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Microsoft Graph API和Azure移动应用程序_Azure_Azure Mobile Services - Fatal编程技术网

Microsoft Graph API和Azure移动应用程序

Microsoft Graph API和Azure移动应用程序,azure,azure-mobile-services,Azure,Azure Mobile Services,我有一个移动应用程序,希望使用Microsoft Graph API进行身份验证。 我正在使用Microsoft.Identity.Client命名空间。我可以通过打电话在那里获得代币 authResult = await App.PublicClientApp.AcquireTokenAsync(_scopes); azureUser = await App.MobileService.LoginWithMicrosoftAccountAsync(authResult.AccessToken

我有一个移动应用程序,希望使用Microsoft Graph API进行身份验证。 我正在使用Microsoft.Identity.Client命名空间。我可以通过打电话在那里获得代币

authResult = await App.PublicClientApp.AcquireTokenAsync(_scopes);
azureUser = await App.MobileService.LoginWithMicrosoftAccountAsync(authResult.AccessToken);
当我通过呼叫将此令牌传递到我的移动应用程序时

authResult = await App.PublicClientApp.AcquireTokenAsync(_scopes);
azureUser = await App.MobileService.LoginWithMicrosoftAccountAsync(authResult.AccessToken);
我收到MobileServiceInvalidOperationException“您没有查看此目录或页面的权限”

我已在应用程序注册门户中注册了我的应用程序。

在Azure中,它看起来像这样:

我错了什么

亲切问候,


Martin

Easy Auth不支持使用Azure AD V2.0发行的访问令牌交换令牌(在本例中使用MSAL库)

要使用移动客户端的客户端流,可以使用OneDrive身份验证库从endpoint for 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;
}
public async Task testeasyautasync()
{
string access_token=await AcquireTokenForLiveAccount();
字符串applicationUrl=”https://mobilefei.azurewebsites.net/";
var mobileClient=新的MobileServiceClient(applicationUrl);
JObject标记=新的JObject();
添加(“访问令牌”,访问令牌);
var user=wait mobileClient.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount,令牌);
Console.WriteLine($“UserID:\n{user.UserID}”);
var result=await mobileClient.InvokeApiAsync(@/.auth/me));
Console.Read();
}
公共异步任务AcquireTokenForLiveAccount()
{
var msAuth=新的MSAuthenticationProvider(“57336bd5-a80f-4b48-a29a-07fdea6ef91e”)https://login.microsoftonline.com/common/oauth2/nativeclient,新字符串[]{“wl.sign”,“wl.offline_access”});
等待msAuth.AuthenticateUserAsync();
返回msAuth.CurrentAccountSession.AccessToken;
}

嗨,你让我高兴极了!它起作用了!非常感谢你!还有一个问题:-(我需要确认此权限的访问:自动登录、始终信息访问、每次登录时应用的基本配置文件。如何存储?提前感谢,相对于应用注册的类型,此问题似乎存在。要解决此问题,您可以注册Live SDK应用程序,而不是聚合应用程序。然后y您可以使用
公共MSAuthenticationProvider(string clientId、string clientSecret、string returnUrl、string[]作用域、CredentialCache CredentialCache);
新建一个
MSAuthenticationProvider
类,并提供机密。