title: Login with Amazon using DotNetOpenAuth returns (400) Bad Request
body: <p>I'm using DotNetOpenAuth on a .NET 3.5 solution to provide social login for our customers. I implemented successfully Facebook, Google and Twitter but I'm stuck at Amazon. I'm using same code for OAuth 2.0 providers but when Amazon loads login screen, I put user and password and when I click login my code crashes on calling ProcessUserAuthorization(), throwing following errors: DNOA complains about: "Error occurred while sending a direct message or getting the response." and inner exception: "The remote server returned an error: (400) Bad Request.".
  Here is my method:</p>
  
  <pre><code>private static AuthenticationDetailsType LoginOauth2(string[] scope = null, Uri return_uri = null)
      {
          try
          {
              // get provider name
              string provider_name = ((LoginProviders)providerID).ToString();
  
              var response = new AuthenticationDetailsType();
  
              // get configuration details
              var token_endpoint = ConfigurationManager.AppSettings[provider_name + "TokenEndPoint"];
              var auth_endpoint = ConfigurationManager.AppSettings[provider_name + "AuthEndPoint"];
              var app_key = ConfigurationManager.AppSettings[provider_name + "AppKey"];
              var app_secret = ConfigurationManager.AppSettings[provider_name + "AppSecret"];
  
              // instantiate a server
              var server = new AuthorizationServerDescription
              {
                  TokenEndpoint = new Uri(token_endpoint),
                  AuthorizationEndpoint = new Uri(auth_endpoint)
              };
  
              // instantiate a client
              var client = new WebServerClient(server)
              {
                  ClientIdentifier = app_key,
                  ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(app_secret)
              };
  
              IAuthorizationState auth_state = client.ProcessUserAuthorization();
  
              if (auth_state == null)
              {
                  client.RequestUserAuthorization(scope, return_uri);
              }
              else
              {
                  response =  new AuthenticationDetailsType
                  {
                      auth_provider = providerID,
                      auth_token = auth_state.AccessToken,
                      auth_token_secret = null,
                      user_id = null
                  };
              }
              return response;
          }
          catch (Exception ex)
          {
              ErrorLogger.ErrorLog.WriteError("Error on loging in with provider " + provider_name + " error: "+ ex.StackTrace.ToString());
              return null;
          }
      }
  </code></pre>
  
  <p>And this are my config keys:</p>
  
  <pre><code>&lt;add key="amazonTokenEndPoint" value="https://api.amazon.com/auth/o2/token"/&gt;
  &lt;add key="amazonAuthEndPoint" value="https://www.amazon.com/ap/oa"/&gt;
  &lt;add key="amazonAppKey" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/&gt;
  &lt;add key="amazonAppSecret" value="xxxxxxxxxxxxxxxxxxxxxxx"/&gt;
  &lt;add key="amazonDetailsRequestEndPoint" value="https://api.amazon.com/user/profile"/&gt;
  &lt;add key="amazonReturnUri" value="https://localhost/SocialLogin.aspx?providerid=x"/&gt;
  </code></pre>
  
  <p>This is how I call this method:</p>
  
  <pre><code>return LoginOauth2(new string[] { "profile" }, new Uri(System.Configuration.ConfigurationManager.AppSettings["amazonReturnUri"]));
  </code></pre>
  
  <p>The exception is thrown at second call of this method, after clicking the Login on Amazon's login screen.</p>
  
  <p>I tried google-ing but I couldn't find resources pointing at my problem.</p>
  
  <p>Thanks for help :)</p>