0
votes

We have implemented ADAL authentication using Dependency service in Xamarin Forms. We have came across a strange issue, when the user's password is recently changed, they are not able to get the access token in their client app.

The expectation is to prompt the user to update the latest credential, in order to get the refreshed access token. But this doesn't seem to work.

Code for UWP:

[assembly: Dependency(typeof(SampleApp.UWP.Helper.Authenticator))]

namespace SampleApp.UWP.Helper { class Authenticator : IAuthenticator {

   public string ReturnUri = Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();
    public async System.Threading.Tasks.Task<AuthenticationResult> Authenticate(string authority, string resource, string clientId, string returnUri=null)
    {
        var authContext = new AuthenticationContext(authority);
        var authResult = await authContext.AcquireTokenAsync(resource, clientId, new Uri(ReturnUri),
            new PlatformParameters(PromptBehavior.Auto,true));
        return authResult;
    } 
}

}

Thanks, Karthik

1
What actually goes wrong? Do you get an error? You have not provided an actual error or problem besides the fact that that piece of code "doesn't work". Most likely people will need more information such as an error description or error behavior to be able to help.Steven Thewissen

1 Answers

0
votes

If you detect the token isn't there (however you are doing that), log them out after you get 'notoken'.

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Windows.Web.Http;
using Windows.Web.Http.Filters;

    public void Logout(AuthenticationContext authContext)
    {
        var filter = new HttpBaseProtocolFilter();
        filter.ClearAuthenticationCache();
        AuthContextHelper.AuthContext.TokenCache.Clear();
        HttpCookieCollection myCookies = filter.CookieManager.GetCookies(new System.Uri(Constants.authority));
        foreach ( HttpCookie cookie in myCookies )
        {
            filter.CookieManager.DeleteCookie(cookie);
        }
    }