/// <summary> /// Transforms an unauthenticated URL to an authenticated one. /// </summary> /// <returns> /// The authenticated URL. /// </returns> /// <param name='account'> /// The <see cref="Account"/> that's been authenticated. /// </param> /// <param name='unauthenticatedUrl'> /// The unauthenticated URL. /// </param> public static Uri GetAuthenticatedUrl(ISalesforceUser account, Uri unauthenticatedUrl) { if (account == null) { throw new ArgumentNullException("account"); } if (!account.Properties.ContainsKey("access_token")) { throw new ArgumentException("OAuth2 account is missing required access_token property.", "account"); } if (unauthenticatedUrl == null) { throw new ArgumentNullException("unauthenticatedUrl"); } var url = unauthenticatedUrl.AbsoluteUri; if (url.Contains("?")) { url += "&access_token=" + account.Properties ["access_token"]; } else { url += "?access_token=" + account.Properties ["access_token"]; } return(new Uri(url)); }
public OAuth2Request ToOAuth2Request (ISalesforceUser user) { if (!(Resource is SObject)) throw new InvalidOperationException ("Only SObjects can have changes. Searches and Queries not elibible."); if (Since > Until) throw new InvalidOperationException ("Since must preceed Until."); // var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; // var baseUri = new Uri (path); // var queryString = String.Format("?start={0:O}&end={1:O}", Since.ToUniversalTime(), Until.ToUniversalTime()); // var changesPath = Path.Combine(Resource.AbsoluteUri.AbsolutePath, ChangeType.ToString(), queryString); // var changesUri = new Uri(changesPath); // var uri = new Uri (baseUri, changesUri); var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri (path); var uri = new UriBuilder(new Uri (baseUri, Resource.AbsoluteUri)); // Custom ISO format: var since = Since.ToUniversalTime(); var sinceString = String.Format("{0}T{1}Z", since.ToString("yyyy-MM-dd"), since.ToString("HH:mm:ss")); var until = Until.ToUniversalTime(); var untilString = String.Format("{0}T{1}Z", until.ToString("yyyy-MM-dd"), until.ToString("HH:mm:ss")); uri.Query = String.Format("start={0}&end={1}", sinceString, untilString); var oauthRequest = new OAuth2Request (Method, uri.Uri, Resource.Options.Where (kvp => kvp.Value.JsonType == JsonType.String).ToDictionary (k => k.Key, v => (string) v.Value), user); return oauthRequest; }
public OAuth2Request ToOAuth2Request(ISalesforceUser user) { if (!(Resource is SObject)) { throw new InvalidOperationException("Only SObjects can have changes. Searches and Queries not elibible."); } if (Since > Until) { throw new InvalidOperationException("Since must preceed Until."); } // var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; // var baseUri = new Uri (path); // var queryString = String.Format("?start={0:O}&end={1:O}", Since.ToUniversalTime(), Until.ToUniversalTime()); // var changesPath = Path.Combine(Resource.AbsoluteUri.AbsolutePath, ChangeType.ToString(), queryString); // var changesUri = new Uri(changesPath); // var uri = new Uri (baseUri, changesUri); var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri(path); var uri = new UriBuilder(new Uri(baseUri, Resource.AbsoluteUri)); // Custom ISO format: var since = Since.ToUniversalTime(); var sinceString = String.Format("{0}T{1}Z", since.ToString("yyyy-MM-dd"), since.ToString("HH:mm:ss")); var until = Until.ToUniversalTime(); var untilString = String.Format("{0}T{1}Z", until.ToString("yyyy-MM-dd"), until.ToString("HH:mm:ss")); uri.Query = String.Format("start={0}&end={1}", sinceString, untilString); var oauthRequest = new OAuth2Request(Method, uri.Uri, Resource.Options.Where(kvp => kvp.Value.JsonType == JsonType.String).ToDictionary(k => k.Key, v => (string)v.Value), user); return(oauthRequest); }
public OAuth2Request ToOAuth2Request (ISalesforceUser user) { var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri (path); var uri = new Uri (baseUri, Resource.AbsoluteUri); var oauthRequest = new OAuth2Request (Method, uri, Resource.Options.Where (kvp => kvp.Value.JsonType == JsonType.String).ToDictionary (k => k.Key, v => (string) v.Value), user); return oauthRequest; }
public OAuth2Request ToOAuth2Request(ISalesforceUser user) { var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri(path); var uri = new Uri(baseUri, Resource.AbsoluteUri); var oauthRequest = new OAuth2Request(Method, uri, Resource.Options.Where(kvp => kvp.Value.JsonType == JsonType.String).ToDictionary(k => k.Key, v => (string)v.Value), user); return(oauthRequest); }
public OAuth2Request ToOAuth2Request (ISalesforceUser user) { var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri (path); var uri = new Uri (baseUri, Resource.AbsoluteUri); var oauthRequest = new OAuth2Request (this.Method, uri, null, Headers, user); return oauthRequest; }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.Request"/> class. /// </summary> /// <param name='method'> /// The HTTP method. /// </param> /// <param name='url'> /// The URL. /// </param> /// <param name='parameters'> /// Parameters that will pre-populate the <see cref="Parameters"/> property or null. /// </param> /// <param name='account'> /// The account used to authenticate this request. /// </param> public Request(string method, Uri url, IDictionary <string, string> parameters = null, ISalesforceUser account = null) { Method = method; Url = url; Parameters = parameters == null ? new Dictionary <string, string> () : new Dictionary <string, string> (parameters); Account = account; }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.Request"/> class. /// </summary> /// <param name='method'> /// The HTTP method. /// </param> /// <param name='url'> /// The URL. /// </param> /// <param name='parameters'> /// Parameters that will pre-populate the <see cref="Parameters"/> property or null. /// </param> /// <param name="headers"></param> /// <param name='account'> /// The account used to authenticate this request. /// </param> public Request (string method, Uri url, IDictionary<string, string> parameters = null, IDictionary<string, string> headers=null, ISalesforceUser account = null) { Method = method; Url = url; Parameters = parameters == null ? new Dictionary<string, string> () : new Dictionary<string, string> (parameters); Headers = headers ?? new Dictionary<string, string>(); Account = account; }
public OAuth2Request ToOAuth2Request(ISalesforceUser user) { var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri(path); var uri = new Uri(baseUri, Resource.AbsoluteUri); var oauthRequest = new OAuth2Request(Method, uri, null, (Xamarin.Auth.Account)user); return(oauthRequest); }
void OnAuthenticationCompleted (AuthenticatorCompletedEventArgs e) { if (!e.IsAuthenticated) { // TODO: Handle failed login scenario by re-presenting login form with error throw new Exception ("Login failed and we don't handle that."); } LoadAccounts (); Account = e.Account; Client.Save (Account); }
void OnAuthenticationCompleted(AuthenticatorCompletedEventArgs e) { if (!e.IsAuthenticated) { // TODO: Handle failed login scenario by re-presenting login form with error throw new Exception("Login failed and we don't handle that."); } LoadAccounts(); Account = e.Account; Client.Save(Account); }
public override void Delete(ISalesforceUser account, string serviceId) { var query = new SecRecord(SecKind.GenericPassword); query.Service = serviceId; query.Account = account.Username; var statusCode = SecKeyChain.Remove(query); if (statusCode != SecStatusCode.Success) { throw new Exception("Could not delete account from KeyChain: " + statusCode); } }
public override void Save(ISalesforceUser account, string serviceId) { var alias = MakeAlias(account, serviceId); var secretKey = new SecretAccount(account); var entry = new KeyStore.SecretKeyEntry(secretKey); ks.SetEntry(alias, entry, prot); lock (fileLock) { using (var s = context.OpenFileOutput(FileName, FileCreationMode.Private)) { ks.Store(s, Password); } } }
public OAuth2Request ToOAuth2Request (ISalesforceUser user) { // We can't update a query or a search object, // so neither of these are appropriate here. if (!(Resource is SObject)) throw new InvalidOperationException ("Only SObjects can be updated. Searches and Queries are read-only."); var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri (path); var uri = new Uri (baseUri, Resource.AbsoluteUri); var r = (SObject)Resource; var options = r.OnPreparingUpdateRequest (); var oauthRequest = new OAuth2Request (this.Method, uri, options,Headers, user); return oauthRequest; }
public OAuth2Request ToOAuth2Request(ISalesforceUser user) { // We can't update a query or a search object, // so neither of these are appropriate here. if (!(Resource is SObject)) { throw new InvalidOperationException("Only SObjects can be updated. Searches and Queries are read-only."); } var path = user.Properties ["instance_url"] + SalesforceClient.RestApiPath; var baseUri = new Uri(path); var uri = new Uri(baseUri, Resource.AbsoluteUri); var r = (SObject)Resource; var options = r.OnPreparingUpdateRequest(); var oauthRequest = new OAuth2Request(Method, uri, options, user); return(oauthRequest); }
public override void Save(ISalesforceUser account, string serviceId) { var statusCode = SecStatusCode.Success; var serializedAccount = account.Serialize(); var data = NSData.FromString(serializedAccount, NSStringEncoding.UTF8); // // Remove any existing record // var existing = FindAccount(account.Username, serviceId); if (existing != null) { var query = new SecRecord(SecKind.GenericPassword); query.Service = serviceId; query.Account = account.Username; statusCode = SecKeyChain.Remove(query); if (statusCode != SecStatusCode.Success) { throw new Exception("Could not save account to KeyChain: " + statusCode); } } // // Add this record // var record = new SecRecord(SecKind.GenericPassword); record.Service = serviceId; record.Account = account.Username; record.Generic = data; record.Accessible = SecAccessible.WhenUnlocked; statusCode = SecKeyChain.Add(record); if (statusCode != SecStatusCode.Success) { throw new Exception("Could not save account to KeyChain: " + statusCode); } }
/// <summary> /// Transforms an unauthenticated URL to an authenticated one. /// </summary> /// <returns> /// The authenticated URL. /// </returns> /// <param name='account'> /// The <see cref="Account"/> that's been authenticated. /// </param> /// <param name='unauthenticatedUrl'> /// The unauthenticated URL. /// </param> public static Uri GetAuthenticatedUrl (ISalesforceUser account, Uri unauthenticatedUrl) { if (account == null) { throw new ArgumentNullException ("account"); } if (!account.Properties.ContainsKey ("access_token")) { throw new ArgumentException ("OAuth2 account is missing required access_token property.", "account"); } if (unauthenticatedUrl == null) { throw new ArgumentNullException ("unauthenticatedUrl"); } var url = unauthenticatedUrl.AbsoluteUri; if (url.Contains ("?")) { url += "&access_token=" + account.Properties ["access_token"]; } else { url += "?access_token=" + account.Properties ["access_token"]; } return new Uri (url); }
public override void Save (ISalesforceUser account, string serviceId) { var statusCode = SecStatusCode.Success; var serializedAccount = account.Serialize (); var data = NSData.FromString (serializedAccount, NSStringEncoding.UTF8); // // Remove any existing record // var existing = FindAccount (account.Username, serviceId); if (existing != null) { var query = new SecRecord (SecKind.GenericPassword); query.Service = serviceId; query.Account = account.Username; statusCode = SecKeyChain.Remove (query); if (statusCode != SecStatusCode.Success) { throw new Exception ("Could not save account to KeyChain: " + statusCode); } } // // Add this record // var record = new SecRecord (SecKind.GenericPassword); record.Service = serviceId; record.Account = account.Username; record.Generic = data; record.Accessible = SecAccessible.WhenUnlocked; statusCode = SecKeyChain.Add (record); if (statusCode != SecStatusCode.Success) { throw new Exception ("Could not save account to KeyChain: " + statusCode); } }
public override void Delete (ISalesforceUser account, string serviceId) { var query = new SecRecord (SecKind.GenericPassword); query.Service = serviceId; query.Account = account.Username; var statusCode = SecKeyChain.Remove (query); if (statusCode != SecStatusCode.Success) { throw new Exception ("Could not delete account from KeyChain: " + statusCode); } }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.OAuth2Request"/> class. /// </summary> /// <param name='method'> /// The HTTP method. /// </param> /// <param name='url'> /// The URL. /// </param> /// <param name='parameters'> /// Parameters that will pre-populate the <see cref="Xamarin.Auth.Request.Parameters"/> property or <see langword="null"/>. /// </param> /// <param name='account'> /// The account used to authenticate this request. /// </param> public OAuth2Request(string method, Uri url, IDictionary <string, string> parameters, ISalesforceUser account) : base(method, url, parameters, account) { }
/// <summary> /// Saves the account to the platform-specific credential store. /// </summary> /// <param name="account">Account.</param> public void Save(ISalesforceUser account) { Debug.WriteLine("Saving user: " + account); Adapter.SaveAccount(account); }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.OAuth2Request"/> class. /// </summary> /// <param name='method'> /// The HTTP method. /// </param> /// <param name='url'> /// The URL. /// </param> /// <param name='parameters'> /// Parameters that will pre-populate the <see cref="Xamarin.Auth.Request.Parameters"/> property or <see langword="null"/>. /// </param> /// <param name='account'> /// The account used to authenticate this request. /// </param> public OAuth2Request (string method, Uri url, IDictionary<string, string> parameters, ISalesforceUser account) : base (method, url, parameters, account) { }
/// <summary> /// Deletes the account for a given serviceId. /// </summary> /// <param name='account'> /// Account to delete. /// </param> /// <param name='serviceId'> /// Service identifier. /// </param> public abstract void Delete (ISalesforceUser account, string serviceId);
public SecretAccount (ISalesforceUser account) { bytes = System.Text.Encoding.UTF8.GetBytes (account.Serialize ()); }
public override void Delete(ISalesforceUser account, string serviceId) { var alias = MakeAlias(account, serviceId); ks.DeleteEntry(alias); }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.AuthenticatorCompletedEventArgs"/> class. /// </summary> /// <param name='account'> /// The account created or <see langword="null"/> if authentication failed or was canceled. /// </param> public AuthenticatorCompletedEventArgs(ISalesforceUser account) { Account = account; }
public void SaveAccount(ISalesforceUser account) { AccountStore.Create(CurrentPlatformContext as Context ?? global::Android.App.Application.Context).Save(account, PlatformStrings.CredentialStoreServiceName); }
public override void Delete (ISalesforceUser account, string serviceId) { var alias = MakeAlias (account, serviceId); ks.DeleteEntry (alias); this.Save(); }
/// <summary> /// Deletes the account for a given serviceId. /// </summary> /// <param name='account'> /// Account to delete. /// </param> /// <param name='serviceId'> /// Service identifier. /// </param> public abstract void Delete(ISalesforceUser account, string serviceId);
static string MakeAlias(ISalesforceUser account, string serviceId) { return(account.Username + "-" + serviceId); }
static string MakeAlias (ISalesforceUser account, string serviceId) { return account.Username + "-" + serviceId; }
public SecretAccount(ISalesforceUser account) { bytes = System.Text.Encoding.UTF8.GetBytes(account.Serialize()); }
public override void Save (ISalesforceUser account, string serviceId) { var alias = MakeAlias (account, serviceId); var secretKey = new SecretAccount (account); var entry = new KeyStore.SecretKeyEntry (secretKey); ks.SetEntry (alias, entry, prot); this.Save(); }
public override void Save (ISalesforceUser account, string serviceId) { var alias = MakeAlias (account, serviceId); var secretKey = new SecretAccount (account); var entry = new KeyStore.SecretKeyEntry (secretKey); ks.SetEntry (alias, entry, prot); lock (fileLock) { using (var s = context.OpenFileOutput (FileName, FileCreationMode.Private)) { ks.Store (s, Password); } } }
/// <summary> /// Initializes a new instance of the <see cref="Xamarin.Auth.AuthenticatorCompletedEventArgs"/> class. /// </summary> /// <param name='account'> /// The account created or <see langword="null"/> if authentication failed or was canceled. /// </param> public AuthenticatorCompletedEventArgs (ISalesforceUser account) { Account = account; }
public void SaveAccount(ISalesforceUser account) { AccountStore.Create().Save(account, PlatformStrings.CredentialStoreServiceName); }