after authentication i am getting only 4 properties in Xamarin.Auth.OAuth2Authenticator .
They are access token,token type,id token and expires in.
And what about authorized code and refresh token.
when i try to upload, it says The access token has expired but we can't refresh it.
Google OAuth2 - The access token has expired but we can't refresh it.
here is my code and help me out on refreshing a token
` authenticator
= new Xamarin.Auth.OAuth2Authenticator
(
clientId: "",
clientSecret: "", // null or ""
authorizeUrl: new Uri("https://accounts.google.com/o/oauth2/auth"), //Uri("https://accounts.google.com/o/oauth2/auth"),
accessTokenUrl: new Uri("https://www.googleapis.com/oauth2/v4/token"),
redirectUrl: new Uri("https://developers.google.com/oauthplayground"),
scope:
//"profile"
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.login"
,
getUsernameAsync: null,
isUsingNativeUI: false
)
{
AllowCancel = true,
};
authenticator.Completed +=
(s, ea) =>
{
StringBuilder sb = new StringBuilder();
//var jsondata = ea.Account.Properties["id_token"];
//jsondata = JsonConvert.DeserializeObject(jsondata);
if (ea.Account != null && ea.Account.Properties != null)
{
sb.Append("Token = ").AppendLine($"{ea.Account.Properties["access_token"]}");
DependencyService.Get<IToken>().SaveTokenData(ea.Account);
App.Current.MainPage = new FilesList();
}
else
{
sb.Append("Not authenticated ").AppendLine($"Account.Properties does not exist");
}
DisplayAlert
(
"Authentication Results",
sb.ToString(),
"OK"
);
return;
};
authenticator.Error +=
(s, ea) =>
{
StringBuilder sb = new StringBuilder();
sb.Append("Error = ").AppendLine($"{ea.Message}");
DisplayAlert
(
"Authentication Error",
sb.ToString(),
"OK"
);
return;
};
// after initialization (creation and event subscribing) exposing local object
AuthenticationState.Authenticator = authenticator;
await Screen(authenticator);
return;`