Created
February 4, 2019 01:49
-
-
Save aimore/9869e8fba1442b44a9cf348468a57bad to your computer and use it in GitHub Desktop.
Xamarin.Auth "Authentication Error: Invalid state from server. Possible forgery!" workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OAuth2AuthenticatorEx : OAuth2Authenticator | |
{ | |
protected override void OnPageEncountered(Uri url, IDictionary<string, string> query, IDictionary<string, string> fragment) | |
{ | |
// Remove state from dictionaries. | |
// We are ignoring request state forgery status | |
// as we're hitting an ASP.NET service which forwards | |
// to a third-party OAuth service itself | |
if (query.ContainsKey("state")) | |
{ | |
query.Remove("state"); | |
} | |
if (fragment.ContainsKey("state")) | |
{ | |
fragment.Remove("state"); | |
} | |
base.OnPageEncountered(url, query, fragment); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a class and add this code below:
public class AuthenticatorExtensions : OAuth2Authenticator
{
public AuthenticatorExtensions(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null, bool isUsingNativeUI = false) : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync, isUsingNativeUI)
{
}
protected override void OnPageEncountered(Uri url, System.Collections.Generic.IDictionary<string, string> query, System.Collections.Generic.IDictionary<string, string> fragment)
{
// Remove state from dictionaries.
// We are ignoring request state forgery status
// as we're hitting an ASP.NET service which forwards
// to a third-party OAuth service itself
if (query.ContainsKey("state"))
{
query.Remove("state");
}
Then use it as below:
[Obsolete]
private void SignInGoogleAuth()
{
try
{
string clientId = null;
string redirectUri = null;
//Xamarin.Auth.CustomTabsConfiguration.CustomTabsClosingMessage = null;