public async Task<bool> SignInUsingIdentityManager()
{
IsSigningIn = true;
// if oauth2 required params are set, register the server for oauth2 authentication.
if (App.IsOrgOAuth2)
{
var serverInfo = new ServerInfo()
{
ServerUri = App.PortalUri.Uri.ToString(),
TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode,
OAuthClientInfo = new OAuthClientInfo() { ClientId = App.AppServerId, RedirectUri = App.AppRedirectUri }
};
IdentityManager.Current.RegisterServer(serverInfo);
}
// check if a TokenCredential can be retrieved without challenging the user
else if (IdentityManager.Current.Credentials.Any())
{
try
{
var credential = IdentityManager.Current.Credentials.ElementAt(0) as TokenCredential;
if (credential != null && !string.IsNullOrEmpty(credential.Token))
{
// set the credential
_credential = credential;
IsSigningIn = false;
return true;
}
}
catch (Exception ex)
{
IsSigningIn = false;
var _ = App.ShowExceptionDialog(ex);
return false;
}
}
// Since a credential could not be retrieved, try getting it by challenging the user
var credentialRequestInfo = new CredentialRequestInfo
{
ServiceUri = App.PortalUri.Uri.ToString(),
AuthenticationType = AuthenticationType.Token,
};
try
{
var credential = await IdentityManager.Current.GetCredentialAsync(credentialRequestInfo, true);
if (credential != null)
{
//set the credential
_credential = credential;
IdentityManager.Current.AddCredential(_credential);
IsSigningIn = false;
return true;
}
}
catch (Exception ex)
{
IsSigningIn = false;
}
IsSigningIn = false;
return false;
}