Azure authentication from push when app is closed

RibsRibs Member ✭✭
edited July 2018 in Xamarin.Forms

I have a Xamarin Forms App that makes a request to a web service passing an chached authentication token after receiving a push notification. This works fine on Android and iPhone when the app is running in the foreground or minimised. But if the app is force closed it will still receive the push notification but will fail getting the cached Azure Authentication Context at this line:
var authContext = new AuthenticationContext(authority);
Giving the error:
Error authenticating: You MUST call Xamarin.Forms.Init(); prior to using it.

This is the same code regardless of whether the app is running or closed.
Can anyone let me know how to authenticate when the app is closed? Or how to call Forms.Init() when a push notification is received.
Any help would be greatly appreciated.

Best Answer

  • RibsRibs ✭✭
    Accepted Answer

    Just in case anyone is experiencing a similar problem; This was caused by the authentication code being in a static method. Moving it to a non-static method fixed the problem.

Answers

  • RibsRibs Member ✭✭
    Accepted Answer

    Just in case anyone is experiencing a similar problem; This was caused by the authentication code being in a static method. Moving it to a non-static method fixed the problem.

Sign In or Register to comment.