Esempio n. 1
0
        /// <summary>
        /// Generate a new API Key with the same permissions that have been granted to you.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="onBehalfOf">The user to impersonate.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>
        /// The <see cref="ApiKey" />.
        /// </returns>
        /// <remarks>
        /// If you specify an API Key when instanciating the <see cref="Client" />, the new API Key will inherit the permissions of that API Key.
        /// If you specify a username and password when instanciating the <see cref="Client" />, the new API Key will inherit the permissions of that user.
        /// </remarks>
        public async Task <ApiKey> CreateWithAllPermissionsAsync(string name, string onBehalfOf = null, CancellationToken cancellationToken = default)
        {
            var scopes = await _client.GetCurrentScopes(true, cancellationToken).ConfigureAwait(false);

            var superApiKey = await this.CreateAsync(name, scopes, onBehalfOf, cancellationToken).ConfigureAwait(false);

            return(superApiKey);
        }
Esempio n. 2
0
        /// <summary>
        /// Send a teammate invitation via email with the same "read" permissions that have been granted to you.
        /// A teammate invite will expire after 7 days, but you may resend the invite at any time
        /// to reset the expiration date.
        /// </summary>
        /// <param name="email">The email address of the teammate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The async task.
        /// </returns>
        /// <remarks>
        /// Essentials, Legacy Lite, and Free Trial users may create up to one teammate per account.
        /// There is not a teammate limit for Pro and higher plans.
        /// </remarks>
        public async Task <TeammateInvitation> InviteTeammateWithReadOnlyPrivilegesAsync(string email, CancellationToken cancellationToken = default)
        {
            var scopes = await _client.GetCurrentScopes(true, cancellationToken).ConfigureAwait(true);

            scopes = scopes.Where(s => s.EndsWith(".read", System.StringComparison.OrdinalIgnoreCase)).ToArray();

            var data = new StrongGridJsonObject();

            data.AddProperty("email", email);
            data.AddProperty("scopes", scopes.ToArray());
            data.AddProperty("is_admin", false);

            return(await _client
                   .PostAsync(_endpoint)
                   .WithJsonBody(data)
                   .WithCancellationToken(cancellationToken)
                   .AsObject <TeammateInvitation>()
                   .ConfigureAwait(false));
        }