예제 #1
0
        private static void ValidateDefaultFormValues(OAuth20GrantBase grant)
        {
            if (grant.ClientId == null)
            {
                throw new ArgumentNullException(nameof(grant.ClientId), $"You are attempting to use {AutomatonConstants.OAuth20.OAUTH_20} grant type {AutomatonConstants.OAuth20.GRANT_TYPE_CLIENT_CREDENTIALS} but the {nameof(grant.ClientId)} is null");
            }

            if (grant.ClientSecret == null)
            {
                throw new ArgumentNullException(nameof(grant.ClientSecret), $"You are attempting to use {AutomatonConstants.OAuth20.OAUTH_20} grant type {AutomatonConstants.OAuth20.GRANT_TYPE_CLIENT_CREDENTIALS} but the {nameof(grant.ClientSecret)} is null");
            }

            if (grant.Scopes == null)
            {
                throw new ArgumentNullException(nameof(grant.Scopes), $"You are attempting to use {AutomatonConstants.OAuth20.OAUTH_20} grant type {AutomatonConstants.OAuth20.GRANT_TYPE_PASSWORD} but the {nameof(grant.Scopes)} list is null");
            }
        }
예제 #2
0
        public static IEnumerable <KeyValuePair <string, string> > CreateUsingGrantType(OAuth20GrantBase grant)
        {
            IEnumerable <KeyValuePair <string, string> > formKeyValuePairs = null;

            switch (grant.GrantType)
            {
            case GrantType.ClientCredentials:
                formKeyValuePairs = CreateUsingClientGrantType((OAuth20ClientGrant)grant);
                break;

            case GrantType.Password:
                formKeyValuePairs = CreateUsingPasswordGrantType((OAuth20PasswordGrant)grant);
                break;

            default:
                break;
            }

            return(formKeyValuePairs);
        }