Hi,
I have a custom page with a pagerenderer for a google oauth2 login. But when the login is succesfull I need to return to my previous page. This is my code:
[assembly: ExportRenderer(typeof(GoogleLoginPage), typeof(GoogleLogin_iOS))]
namespace iBridge_RandstadMetaApp.iOS
{
public class GoogleLogin_iOS : PageRenderer
{
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(false);
var auth = new OAuth2Authenticator(
clientId: App.GoogleApiClientId,
clientSecret: App.GoogleApiClientSecret,
scope: "email",
authorizeUrl: new Uri("https://accounts.google.com/o/oauth2/auth"),
redirectUrl: new Uri(App.GoogleApiRedirectUrl2),
accessTokenUrl: new Uri("https://accounts.google.com/o/oauth2/token"),
getUsernameAsync: null
);
auth.Title = App.GetTextFromKey("Login");
auth.AllowCancel = false;
auth.Completed += (sender, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
// Use eventArgs.Account to do wonderful things
string code = "";
eventArgs.Account.Properties.TryGetValue("access_token", out code);
Console.WriteLine("ac: " + code);
App.GoogleApiAccesToken = code;
eventArgs.Account.Properties.TryGetValue("refresh_token", out code);
Console.WriteLine("rc: " + code);
NavHelper.Nav.NavigateToValidationPageAction.Invoke();
}
};
PresentViewController(auth.GetUI(), false, null);
}
}
}
public class NavHelper
{
static volatile NavHelper _nav;
static object _SyncRoot = new Object();
public static NavHelper Nav
{
get
{
if (_nav == null)
{
lock (_SyncRoot)
{
if (_nav == null)
{
_nav = new NavHelper();
}
}
}
return _nav;
}
}
public NavigationPage NavPage { get; set; }
public Action NavigateToValidationPageAction
{
get
{
return new Action(() =>
{
App.LoginOk = true;
//NavPage.Navigation.PushModalAsync(new ValidationPage());
if (Device.OS == TargetPlatform.iOS)
{
NavPage.Navigation.PopModalAsync();
//NavPage.Navigation.PushModalAsync(new ValidationPage());
}
else if (Device.OS == TargetPlatform.Android) {
//NavPage.Navigation.PopModalAsync();
NavPage.Navigation.PushModalAsync(new ValidationPage());
}
});
}
}
}