Hello,
I’m trying to implement Xamarin.Auth (OAuth 2) with Google in UWP.
After login, the browser close and I go back to my app but the event “Completed” is not fired.
Here is my code :
The “ButtonClicked” event of my “Google Login” button :
if (Device.RuntimePlatform == Device.UWP || Device.RuntimePlatform == Device.iOS)
{
App.OOAuth = new OAuth2Authenticator(App.CIdClientGoogleIOSUWP,
string.Empty,
"email",
new Uri(App.CUrlAuthorizeGoogle),
new Uri(App.CUrlRedirectGoogleIOSUWP.Trim()),
new Uri(App.CUrlTokenGoogle),
isUsingNativeUI: true);
}
App.OOAuth.Completed -= AuthGoogle_Completed;
App.OOAuth.Completed += AuthGoogle_Completed;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(App.OOAuth);
My redirect url is custom : “com.XXXX.apps:/oauth2redirect”.
I added the right protocol in “Package.appxmanifest” :
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="com.XXXX.apps" />
</uap:Extension>
</Extensions>
In “App.xaml.cs” of the UWP project, I overrided the OnActivated event :
protected override void OnActivated(IActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(args);
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (args.Kind == ActivationKind.Protocol)
{
var protocolArgs = args as ProtocolActivatedEventArgs;
rootFrame.Navigate(typeof(MainPage), protocolArgs.Uri);
}
else
{
rootFrame.Navigate(typeof(MainPage));
}
// Ensure the current window is active
Window.Current.Activate();
}
So, the redirection is Ok but my event “AuthGoogle_Completed” is not triggered.
Did I do something wrong ? Or did I miss something ?
Thanks in advance for your help.