This feature - authentication based on information from a client-side SDK for Microsoft accounts (live SDK) or Facebook - is currently not supported in the .NET backend for mobile services. What the .NET backend supports is either the authentication via the web interface for Microsoft/Facebook/Google/Twitter, or client-side authentication for Azure Active Directory. The support for the feature you want should be implemented in a coming release. You can check out the Azure Mobile team blog for announcements on when it is live.
LoginWithMicrosoftAccountAsync always fails with 401
-
20-07-2023 - |
Question
I have created a universal app and an azure mobile services. I followed the tutorial on adding microsoft account authentication as is provided at the azure website. I am using the newest Live SDK for this purpose.
Client side, i am using this code, which is more or less straigt out of the tutorial:
const string ReferralUrl = "https://my-url-here.azure-mobile.net/";
static MobileServiceClient MobileService = new MobileServiceClient(
"https://my-url-here.azure-mobile.net/",
"my key");
MobileServiceUser _user;
private LiveConnectSession _session;
private async Task Authenticate()
{
var authClient = new LiveAuthClient(ReferralUrl);
while (_session == null)
{
var result = await authClient.LoginAsync(new[] { "wl.basic" });
if (result.Status == LiveConnectSessionStatus.Connected)
{
_session = result.Session;
var client = new LiveConnectClient(result.Session);
var meResult = await client.GetAsync("me");
return;
}
else
{
break;
}
}
_session = null;
}
public async Task<bool> Login()
{
try
{
await Authenticate();
_user = await MobileService
.LoginWithMicrosoftAccountAsync(_session.AuthenticationToken);
}
catch (Exception ex)
{
//Debug.WriteLine(ex.Message);
//return false;
}
return true;
}
The following facts have been verified for this application:
- The store entry has been created
- The store entry has been associated with the universal app (this has been performed for both, win8.1 and wp8.1 projects)
- The store app has the following settings:
- mobile or desktop: yes
- jwt: yes
- security: activated
- redirection url: is set to https://my-url-here.azure-mobile.net/login/microsoftaccount
At the azure portal, in the identity tab, the client id and secret have been entered and saved. However, there is no package-SID (this is also not mentioned in the tutorial).
I downloaded the service project that is created with the mobile service and added it to my solution. Also, I have added the SetIsHosted(true) flag to the WebApiConfig class. Finally i added the AuthorizeLevel attribute to the TodoItemController and set it to User Level. The service has been successfully published to azure.
When i run my application and call Login, it will result in a 401 exception. It doesnt matter if i run it local or hosted.
Any ideas?
Solution