Exemplo n.º 1
0
        private static void ValidatePasswordFormValues(OAuth20PasswordGrant grant)
        {
            if (grant.Username == null)
            {
                throw new ArgumentNullException(nameof(grant.Username), $"You are attempting to use {AutomatonConstants.OAuth20.OAUTH_20} grant type {AutomatonConstants.OAuth20.GRANT_TYPE_PASSWORD} but the {nameof(grant.Username)} is null");
            }

            if (grant.UserPassword == null)
            {
                throw new ArgumentNullException(nameof(grant.UserPassword), $"You are attempting to use {AutomatonConstants.OAuth20.OAUTH_20} grant type {AutomatonConstants.OAuth20.GRANT_TYPE_PASSWORD} but the {nameof(grant.UserPassword)} is null");
            }
        }
Exemplo n.º 2
0
        private static IEnumerable <KeyValuePair <string, string> > CreateUsingPasswordGrantType(OAuth20PasswordGrant grant)
        {
            List <KeyValuePair <string, string> > formKeyValuePairs = new List <KeyValuePair <string, string> >();

            ValidateDefaultFormValues(grant);
            ValidatePasswordFormValues(grant);

            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.GRANT_TYPE, AutomatonConstants.OAuth20.PASSWORD));
            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.CLIENT_ID, grant.ClientId));
            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.CLIENT_SECRET, grant.ClientSecret));
            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.USERNAME, grant.Username));
            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.PASSWORD, grant.UserPassword));
            formKeyValuePairs.Add(new KeyValuePair <string, string>(AutomatonConstants.OAuth20.SCOPE, grant.Scopes));

            return(formKeyValuePairs);
        }