/// <summary> /// Create an <see cref="AuthenticationRequest"/> using the specified username and API key as credentials. /// </summary> /// <param name="username">The account username.</param> /// <param name="apiKey">The account API key.</param> /// <returns> /// <para>An <see cref="AuthenticationRequest"/> instance containing the specified credentials, which is /// typically used for constructing an instance of <see cref="RackspaceAuthenticationService"/>.</para> /// </returns> /// <exception cref="ArgumentNullException"> /// <para>If <paramref name="username"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="apiKey"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para>If <paramref name="username"/> is empty.</para> /// <para>-or-</para> /// <para>If <paramref name="apiKey"/> is empty.</para> /// </exception> public static AuthenticationRequest ApiKey(string username, string apiKey) { if (username == null) throw new ArgumentNullException("username"); if (apiKey == null) throw new ArgumentNullException("apiKey"); if (string.IsNullOrEmpty(username)) throw new ArgumentException("username cannot be empty"); if (string.IsNullOrEmpty(apiKey)) throw new ArgumentException("apiKey cannot be empty"); var extensionData = ImmutableDictionary<string, JToken>.Empty .Add("RAX-KSKEY:apiKeyCredentials", new JObject( new JProperty("username", username), new JProperty("apiKey", apiKey))); AuthenticationData authenticationData = new AuthenticationData(extensionData); AuthenticationRequest authenticationRequest = new AuthenticationRequest(authenticationData); return authenticationRequest; }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationRequest"/> class /// with the specified extension data. /// </summary> /// <param name="auth">An <see cref="AuthenticationData"/> which specifies the value for the <c>auth</c> /// property in the JSON representation of an authentication request in the OpenStack Identity Service /// V2.</param> /// <param name="extensionData">The extension data.</param> /// <remarks> /// <para> /// The default authentication request places credentials within an <c>auth</c> property in the JSON /// representation. The following block shows an example representation. /// </para> /// <code language="none"> /// { /// "auth" : {AuthenticationData...}, /// extensionData... /// } /// </code> /// <para> /// To specify credentials for a vendor which uses a non-standard form of the request which does not include the /// authentication credentials within an <c>auth</c> property in the JSON representation of the request, pass /// <see langword="null"/> for the <paramref name="auth"/> argument and use the <paramref name="extensionData"/> /// argument to specify the complete set of properties for the authentication request. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"> /// If <paramref name="extensionData"/> is <see langword="null"/>. /// </exception> public AuthenticationRequest(AuthenticationData auth, ImmutableDictionary<string, JToken> extensionData) : base(extensionData) { _auth = auth; }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationRequest"/> class with the specified /// authentication data. /// </summary> /// <param name="auth">An <see cref="AuthenticationData"/> which specifies the value for the <c>auth</c> /// property in the JSON representation of an authentication request in the OpenStack Identity Service /// V2.</param> /// <remarks> /// <para> /// The default authentication request places credentials within an <c>auth</c> property in the JSON /// representation. The following block shows an example representation. /// </para> /// <code language="none"> /// { /// "auth" : {AuthenticationData...} /// } /// </code> /// <para> /// To specify credentials for a vendor which uses a non-standard form of the request which does not include the /// authentication credentials within an <c>auth</c> property in the JSON representation of the request, see /// <see cref="AuthenticationRequest(AuthenticationData, ImmutableDictionary{string, JToken})"/>. /// </para> /// </remarks> public AuthenticationRequest(AuthenticationData auth) { _auth = auth; }
/// <summary> /// Create an <see cref="AuthenticationRequest"/> using the specified username and password as credentials. /// </summary> /// <remarks> /// <note type="warning"> /// For improved security, clients are encouraged to use API key credentials instead of a password whenever /// possible. /// </note> /// </remarks> /// <param name="username">The account username.</param> /// <param name="password">The account password.</param> /// <returns> /// <para>An <see cref="AuthenticationRequest"/> instance containing the specified credentials, which is /// typically used for constructing an instance of <see cref="RackspaceAuthenticationService"/>.</para> /// </returns> /// <exception cref="ArgumentNullException"> /// <para>If <paramref name="username"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="password"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para>If <paramref name="username"/> is empty.</para> /// <para>-or-</para> /// <para>If <paramref name="password"/> is empty.</para> /// </exception> public static AuthenticationRequest Password(string username, string password) { if (username == null) throw new ArgumentNullException("username"); if (password == null) throw new ArgumentNullException("password"); if (string.IsNullOrEmpty(username)) throw new ArgumentException("username cannot be empty"); if (string.IsNullOrEmpty(password)) throw new ArgumentException("password cannot be empty"); PasswordCredentials passwordCredentials = new PasswordCredentials(username, password); AuthenticationData authenticationData = new AuthenticationData(passwordCredentials); AuthenticationRequest authenticationRequest = new AuthenticationRequest(authenticationData); return authenticationRequest; }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationRequest"/> class /// with the specified extension data. /// </summary> /// <param name="auth">An <see cref="AuthenticationData"/> which specifies the value for the <c>auth</c> /// property in the JSON representation of an authentication request in the OpenStack Identity Service /// V2.</param> /// <param name="extensionData">The extension data.</param> /// <remarks> /// <para> /// The default authentication request places credentials within an <c>auth</c> property in the JSON /// representation. The following block shows an example representation. /// </para> /// <code language="none"> /// { /// "auth" : {AuthenticationData...}, /// extensionData... /// } /// </code> /// <para> /// To specify credentials for a vendor which uses a non-standard form of the request which does not include the /// authentication credentials within an <c>auth</c> property in the JSON representation of the request, pass /// <see langword="null"/> for the <paramref name="auth"/> argument and use the <paramref name="extensionData"/> /// argument to specify the complete set of properties for the authentication request. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"> /// If <paramref name="extensionData"/> is <see langword="null"/>. /// </exception> public AuthenticationRequest(AuthenticationData auth, ImmutableDictionary <string, JToken> extensionData) : base(extensionData) { _auth = auth; }