简体   繁体   中英

Azure App Services Authentication

Has anyone been able to figure out authentication using Azure App Services?

For some strange reason it is no longer handling refresh tokens like it used to in Mobile Services, the token I'm now caching expires in 1 hour, this is useless.

It's a C# UWP app, I'm using Microsoft Account as the login, I've been told to use the OneDrive API to login and retrieve the token and then use that to login to App Services, that doesn't work for me either, with an error like "you do not have permission to access the directory".

Any help is appreciated.

A solution for App Service Mobile, the update to MobileService. There should now be a solution

The code replicated here is:

async Task<string> GetDataAsync()
{
try
{
    return await App.MobileService.InvokeApiAsync<string>("values");
}
catch (MobileServiceInvalidOperationException e)
{
    if (e.Response.StatusCode != HttpStatusCode.Unauthorized)
    {
        throw;
    }
}

// Calling /.auth/refresh will update the tokens in the token store
// and will also return a new mobile authentication token.
JObject refreshJson = (JObject)await App.MobileService.InvokeApiAsync(
    "/.auth/refresh",
    HttpMethod.Get,
    null);

string newToken = refreshJson["authenticationToken"].Value<string>();
App.MobileService.CurrentUser.MobileServiceAuthenticationToken
    = newToken;
return await App.MobileService.InvokeApiAsync<string>("values");
}

Hope it saves somebody time !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM