AmazonClient ClassNemiro.OAuth
OAuth client for Amazon.
Inheritance Hierarchy

System Object
  Nemiro.OAuth OAuthBase
    Nemiro.OAuth OAuth2Client
      Nemiro.OAuth.Clients AmazonClient

Namespace: Nemiro.OAuth.Clients
Assembly: Nemiro.OAuth (in Nemiro.OAuth.dll) Version: 1.9.4.725 (1.9.4.725)
Syntax

public class AmazonClient : OAuth2Client

The AmazonClient type exposes the following members.

Constructors

  NameDescription
Public methodAmazonClient
Initializes a new instance of the AmazonClient class.
Top
Methods

  NameDescription
Public methodClone 
Creates a shallow copy of the current object.
(Inherited from OAuthBase.)
Public methodClone(NameValueCollection, String)
Creates a shallow copy of the current object.
(Inherited from OAuthBase.)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Protected methodGetAccessToken
Gets the access token from the remote server.
(Inherited from OAuth2Client.)
Public methodGetHashCode (Inherited from Object.)
Protected methodGetSpecifiedTokenOrCurrent
Returns the specified access token or the current access token.
(Inherited from OAuthBase.)
Public methodGetType (Inherited from Object.)
Public methodGetUserInfo Obsolete.
Gets the user details via API of the provider.
(Inherited from OAuthBase.)
Public methodGetUserInfo(AccessToken)
Gets the user details.
(Overrides OAuthBase GetUserInfo(AccessToken).)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRedirectToAuthorization
Redirects a client to the Authorization URL.
(Inherited from OAuthBase.)
Public methodRefreshToken
Sends a request to refresh the access token.
(Overrides OAuth2Client RefreshToken(AccessToken).)
Public methodRevokeToken
Sends a request to revoke the access token.
(Inherited from OAuthBase.)
Public methodToString (Inherited from Object.)
Top
Properties

  NameDescription
Public propertyAccessToken
Gets or sets an access token.
(Inherited from OAuthBase.)
Protected propertyAccessTokenUrl
Gets or sets the address for the access token.
(Inherited from OAuthBase.)
Public propertyAccessTokenValue
Gets an access token value.
(Inherited from OAuthBase.)
Public propertyApplicationId
Gets or sets the application identifier.
(Inherited from OAuthBase.)
Public propertyApplicationSecret
Gets or sets the application secret key.
(Inherited from OAuthBase.)
Public propertyAuthorizationCode
Gets or sets access code for access token requests.
(Inherited from OAuthBase.)
Public propertyAuthorizationUrl
Gets the endpoint of the authorization.
(Inherited from OAuth2Client.)
Protected propertyAuthorizeUrl
Gets or sets the base address for login.
(Inherited from OAuthBase.)
Public propertyDefaultScope
The deault scope.
(Inherited from OAuth2Client.)
Public propertyGrantType
Gets or sets grant type.
(Inherited from OAuth2Client.)
Public propertyParameters
Gets or sets additional query parameters.
(Inherited from OAuthBase.)
Public propertyPassword
Gets or sets password if GrantType is password or client_credentials.
(Inherited from OAuth2Client.)
Public propertyProviderName
Unique provider name: Amazon.
(Overrides OAuthBase ProviderName.)
Public propertyReturnUrl
Gets or sets return URL.
(Inherited from OAuthBase.)
Public propertyScope
The scope of the access request.
(Inherited from OAuth2Client.)
Public propertyScopeSeparator
The separator in the scope list.
(Inherited from OAuth2Client.)
Public propertyState
Gets or sets unique request identifier. For clients the value sets is automatically.
(Inherited from OAuthBase.)
Public propertySupportRefreshToken
Gets or sets a value indicating whether the current client supports refreshing access token.
(Inherited from OAuthBase.)
Public propertySupportRevokeToken
Gets or sets a value indicating whether the current client supports revoking access token.
(Inherited from OAuthBase.)
Public propertyUsername
Gets or sets username if GrantType is password or client_credentials.
(Inherited from OAuth2Client.)
Public propertyVersion
Gets the version of the OAuth protocol.
(Inherited from OAuthBase.)
Top
Remarks

Register and Configure Amazon Application

(!)Web Management Interface may change over time. Applications registration shown below may differ.
If the interface is changed, you need to register the application and get Client ID and Client Secret. For web projects, configure return URLs.
If you have any problems with this, please visit issues. If you do not find a solution to your problem, you can create a new question.

You need to register as developer in the App Console.

Sign in to the App Console

In the App Console register new application.

Register new application

Specify one or more return URLs. Access to any other address will be denied.

NOTE: Amazon supports only addresses over HTTPS (excluding localhost).

For example:

  • https://hamster.example.org/Home/ExternalLoginResult
  • http://localhost:59962/Home/ExternalLoginResult
  • http://localhost/

Allowed Return URLs

Do not forget to save your changes.

Use application Client ID and Client Secret when creating an instance of the AmazonClient class.

Allowed Return URLs

OAuthManager.RegisterClient
(
  new AmazonClient
  (
    "amzn1.application-oa2-client.f0ffe4edc256488dae00dcaf96d75d1b", 
    "764dcefe49b441c8c6244c93e5d5d04de54fda6dfdc83da9693bf346f4dc4515"
  )
);

For more details, please see Amazon Developer Documentation.

Examples

The following example shows how to add the Amazon OAuth Client to ASP .NET MVC Application.

In the Application_Start event handler (Global.asax file) is registered the AmazonClient.

protected void Application_Start()
{
  OAuthManager.RegisterClient
  (
    new AmazonClient
    (
      "amzn1.application-oa2-client.f0ffe4edc256488dae00dcaf96d75d1b", 
      "764dcefe49b441c8c6244c93e5d5d04de54fda6dfdc83da9693bf346f4dc4515"
    )
  );
}

The ExternalLoginResult method will handle authorization result.

public ActionResult ExternalLoginResult()
{
  var result = OAuthWeb.VerifyAuthorization();
  if (result.IsSuccessfully)
  {
    var user = result.UserInfo;    
    // NOTE: For StringBuilder import the System.Text
    StringBuilder r = new StringBuilder();
    r.AppendFormat("User ID: {0}\r\n", user.UserId);
    r.AppendFormat("Name:    {0}\r\n", user.DisplayName);
    r.AppendFormat("Email:   {0}", user.Email);
    return new ContentResult { Content = r.ToString(), ContentType = "text/plain" }; 
  }

  return new ContentResult 
  { 
    Content = "Error: " + result.ErrorInfo.Message, 
    ContentType = "text/plain" 
  };
}

Now you can easily redirect user to login page.

// NOTE: use httpS scheme for real websites 
string authUrl = OAuthWeb.GetAuthorizationUrl("Amazon", Url.Action("ExternalLoginResult", "Home", null, null, Request.Url.Host));
// for example, MVC redirection from Action: 
// return Redirect(authUrl);

Result shown in the images below.

Amazon Sign in

Amazon User Info

See Also

Nemiro.OAuth.Clients AmazonClient