コード例 #1
0
        private async Task <ChannelCredentials> CreateChannelCredentialsUncached()
        {
            var appDefaultCredentials = await EnfonicaCredential.GetApplicationDefaultAsync().ConfigureAwait(false);

            if (appDefaultCredentials.IsCreateScopedRequired)
            {
                appDefaultCredentials = appDefaultCredentials.CreateScoped(_scopes);
            }
            return(appDefaultCredentials.ToChannelCredentials());
        }
コード例 #2
0
        /// <summary>
        /// Creates a new <see cref="ServiceAccountCredential"/> instance from JSON credential data.
        /// </summary>
        /// <param name="credentialData">The stream from which to read the JSON key data for a service account. Must not be null.</param>
        /// <exception cref="InvalidOperationException">
        /// The <paramref name="credentialData"/> does not contain valid JSON service account key data.
        /// </exception>
        /// <returns>The credentials parsed from the service account key data.</returns>
        public static ServiceAccountCredential FromServiceAccountData(Stream credentialData)
        {
            var credential = EnfonicaCredential.FromStream(credentialData);
            var result     = credential.UnderlyingCredential as ServiceAccountCredential;

            if (result == null)
            {
                throw new InvalidOperationException("JSON data does not represent a valid service account credential.");
            }
            return(result);
        }
コード例 #3
0
        /// <summary>Creates a default credential from JSON data.</summary>
        private static EnfonicaCredential CreateDefaultCredentialFromParameters(JsonCredentialParameters credentialParameters)
        {
            switch (credentialParameters.Type)
            {
            case JsonCredentialParameters.ServiceAccountCredentialType:
                return(EnfonicaCredential.FromServiceAccountCredential(
                           CreateServiceAccountCredentialFromParameters(credentialParameters)));

            default:
                throw new InvalidOperationException(
                          String.Format("Error creating credential from JSON. Unrecognized credential type {0}.",
                                        credentialParameters.Type));
            }
        }