AddCredential() public static method

Adds a credential to the isolated storage.
public static AddCredential ( Credential credential ) : void
credential Credential The credential to be added.
return void
 // get a OAuth token
 private async Task<Credential> CreateOAuthCredentialAsync(CredentialRequestInfo credentialRequestInfo)
 {
     TokenCredential credential = await IdentityManager.Current.GenerateCredentialAsync(credentialRequestInfo.ServiceUri, credentialRequestInfo.GenerateTokenOptions);
     if (AllowSaveCredentials)
         CredentialManager.AddCredential(credential);
     return credential;
 }
 // Display the sign in dialog and create a credential 
 private async Task<Credential> SignInDialogCreateCredentialAsync(CredentialRequestInfo credentialRequestInfo)
 {
     Credential credential = await _signInDialog.CreateCredentialAsync(credentialRequestInfo);
     if (AllowSaveCredentials && _signInDialog.CredentialSaveOption != CredentialSaveOption.Unselected)
         CredentialManager.AddCredential(credential);
     CredentialSaveOption = _signInDialog.CredentialSaveOption; // so a custom component can use it
     return credential;
 }
        private Task <Credential> CreateCertificateCredentialAsync(CredentialRequestInfo credentialRequestInfo)
        {
            var tcs   = new TaskCompletionSource <Credential>();
            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            X509Certificate2Collection certificates;

            try
            {
                const string clientAuthOid = "1.3.6.1.5.5.7.3.2"; // Client Authentication OID
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                // Find Client Authentication certificate
                certificates = store.Certificates.Find(X509FindType.FindByApplicationPolicy, clientAuthOid, true);
            }
            catch (Exception)
            {
                certificates = null;
            }
            finally
            {
                store.Close();
            }

            string     url        = credentialRequestInfo.ServiceUri;
            ServerInfo serverInfo = IdentityManager.Current.FindServerInfo(url);

            if (certificates != null && certificates.Count >= 1)
            {
                // Let the user select/validate the certificate
                string resourceName = GetResourceName(url);
                string server       = serverInfo == null?Regex.Match(url, "http.?//[^/]*").ToString() : serverInfo.ServerUri;

                string message = resourceName == null
                    ? string.Format("certificate required to access to {0}", server)
                    : string.Format("certificate required to access {0} on {1}", resourceName, server);

                certificates = X509Certificate2UI.SelectFromCollection(certificates, null, message, X509SelectionFlag.SingleSelection);
            }

            if (certificates != null && certificates.Count > 0)
            {
                var credential = new CertificateCredential(certificates[0])
                {
                    ServiceUri = serverInfo == null ? url : serverInfo.ServerUri
                };
                if (AllowSaveCredentials)
                {
                    CredentialManager.AddCredential(credential);
                }

                tcs.TrySetResult(credential);
            }
            else
            {
                // Note : Error type is not that important since the error returned to the user is the initial HTTP error (Authorization Error)
                tcs.TrySetException(new System.Security.Authentication.AuthenticationException());
            }
            return(tcs.Task);
        }
        // Display the sign in dialog and create a credential
        private async Task <Credential> SignInDialogCreateCredentialAsync(CredentialRequestInfo credentialRequestInfo)
        {
            Credential credential = await _signInDialog.CreateCredentialAsync(credentialRequestInfo);

            if (AllowSaveCredentials && _signInDialog.CredentialSaveOption != CredentialSaveOption.Unselected)
            {
                CredentialManager.AddCredential(credential);
            }
            return(credential);
        }