Skip to content

Latest commit

 

History

History
113 lines (59 loc) · 6.31 KB

README.md

File metadata and controls

113 lines (59 loc) · 6.31 KB

OAuth Sample Application

This repository contains a sample application which demonstrates connecting to Authorize.Net using the OAuth 2.0 authentication standard.

How to Use the Sample Application?

  • Clone or download this repository.
  • Open solution OAuthDemo.sln in Visual Studio and set OAuthDemo as StartUp project
  • Run OAuthDemo.sln from Visual studio to launch the application. Application runs on local IIS server.

alt text

  • ClientId and ClientSecret values can be obtained by contacting Authorize.Net support team at [email protected] and providing a RedirectUri(This is the page that the merchant is redirected back to after granting permissions) for your application.

Sample ClientId and ClientSecret shown in the below screen can be used for the demo purpose and can later be replaced in the code with newly obtained ClientId and ClientSecret.

File - DemoModel.cs

public Demo()

    {

        ClientId = "4dp5b7gRqk";

        ClientSecret = "fa3a5b16753d09b24bb44243605a4a98";

alt text

  • Click Continue to go to the next step to obtain OAuth code.

alt text

  • ClientId and RedirectUri values are used to get OAuth code.

  • Check/Uncheck Read and Write boxes to specify the level of access that the application is requesting.

  • State value is echoed back in the response to protect against malicious interception.

  • Sub value should be oauth.

  • Click Redirect to Authorize.net

alt text

  • Login with your Authorize.net credentials to allow access. alt text
  • Click Allow. Page will be redirected to https://developer.authorize.net with generated authorization code in the url. Copy the authorization code to obtain access and refresh token.

alt text

  • Go back to OAuth demo application. Click Continue. Use the authorization code obtained from previous step. Click Submit Token Request.

alt text

  • Access Token and Refresh Token will be part of Response.Copy Access Token from Response. Click Continue.

alt text

Sample Response-

{

"access_token": "eyJraWQiOiI5YzIwNzk0MGJiNzhkODc5MDAwMDAwMDA1NGNjY2Q2NyIsImFsZyI6IlJTMjU2In0.eyJqdGkiOiJkYmM0YzMyYS1jN2FhLTQ5ZTgtYmY3NS02NzI2Y2VjMmNjYzAiLCJzY29wZXMiOlsicmVhZCIsIndyaXRlIl0sImlhdCI6MTUyMjEwNDUwOTE4MCwiYXNzb2NpYXRlZF9pZCI6IjM4MDQiLCJjbGllbnRfaWQiOiI0ZHA1Yjdn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widG9rZW5fdHlwZSI6InJlZnJlc2hfdG9rZW4iLCJncmFudF90eXBlIjoiYXV0aG9yaXphdGlvbl9jb2RlIn0.inttrtVxgrlq-NusLxmbNNJDcLE69BtFACjwxVo1rByuWHX9pVy4FDrKy_SB8p_yX1TlB_RX0EmwojYY0gGQspP5F9H2ozPJoZaQoJM5idAYIHh38oduJEHTrBLNDjqWpAf4TBNKoSJlqvi5w9_0uun5G9r7b-MMt9cMrKaKOyDbLuJ51I7OOqUDUh3kS0RQa8BJmPRkTIRrAH_VKbaBL3sxyz-vdBMxsc5ILbWxOKnFn_azcTt1ORLzoBTP6BJFaTIpMdxCvruf8M_isJhbsJKQwaUa7yu89JJ0yXbEKVSFRZhlnwn0RaTgo7foxqX-9emG1dh5SdFAfgV7gZD9YA",

"expires_in": 28799,

"scope": "read write",

"refresh_token_expires_in": 28799,

"client_status": "active"

}

  • Use the Access Token to authenticate transactions. Test Write and Read transaction APIs using Access Token.

alt text

alt text

  • To retrieve a new pair of tokens, use the refresh token obtained in Retrieve step.

alt text

  • Use the refreshed Access Token for subsequent requests.

alt text

  • To revoke permissions. Click Redirect to Revoke.

Refresh Token is revoked immediately. Any previously issued Access Token will be valid till they expire.

alt text

  • Click Revoke Permissions

alt text

  • Click Revoke Permissions

Note: If the OAuthDemo application is running on a network which is behind a proxy, you may have to add below settings in the web.config file of the OAuth Demo application project to access the API endpoint.

<system.net>

                &lt;defaultProxyuseDefaultCredentials=&quot;true&quot;enabled=&quot;true&quot;&gt;

                &lt;/defaultProxy&gt;

</system.net>