// Initialize client
OAuthTokenClient oAuth = new OAuthTokenClient();
Dictionary<string, object> authUrlRequest = new Dictionary<string, object>();
authUrlRequest.Add("client_id","<YOUR_CLIENT_ID>");
authUrlRequest.Add("redirect_uri","https://example.com/razorpay_callback");
authUrlRequest.Add("scopes", new List<string> {"read_only", "rx_read_write"});
authUrlRequest.Add("state","NOBYtv8r6c75ex6WZ");
Dictionary<string, object> attributes = new Dictionary<string, object>();
attributes.Add("submerchant_id", "<SUBMERCHANT_MID>");
attributes.Add("timestamp", DateTimeOffset.UtcNow.ToUnixTimeSeconds());
string onboardingSignature = Utils.GenerateOnboardingSignature(attributes, "<YOUR_CLIENT_SECRET>");
authUrlRequest.Add("onboarding_signature",onboardingSignature);
String authUrl = oAuth.GetAuthUrl(authUrlRequest);
Parameters:
Name | Type | Description |
---|---|---|
client_id* | string | Unique client identifier. |
redirect_uri* | string | Callback URL used by Razorpay to redirect after the user approves or denies the authorisation request. The client should whitelist the 'redirect_uri'. |
scopes* | List | Defines what access your application is requesting from the user. You can request one or multiple scopes by adding them to the list as indicated above. |
state* | string | A random string generated by your service. This parameter helps prevent cross-site request forgery (CSRF) attacks. |
onboarding_signature | string | A cryptographic string generated by your service using generateOnboardingSignature method in Utils class. Only applicable for accounts created with pre-fill KYC |
Response:
"https://auth.razorpay.com/authorize?response_type=code&client_id=<YOUR_CLIENT_ID>&redirect_uri=https:%2F%2Fexample.com%2Frazorpay_callback&scope[]=read_only&scope[]=rx_read_write&state=NOBYtv8r6c75ex6WZ&onboarding_signature=<GENERATED_ONBOARDING_SIGNATURE>"
Dictionary<string, object> accessTokenRequest = new Dictionary<string, object>();
accessTokenRequest.Add("client_id","<YOUR_CLIENT_ID>");
accessTokenRequest.Add("client_secret","<YOUR_CLIENT_SECRET>");
accessTokenRequest.Add("redirect_uri","https://example.com");
accessTokenRequest.Add("grant_type","authorization_code");
accessTokenRequest.Add("code","def50200d844dc80cc44dce2c665d07a374d76802");
accessTokenRequest.Add("mode","test");
OAuthTokenClient oAuthTokenClient = oAuth.GetAccessToken(accessTokenRequest);
Parameters:
Name | Type | Description |
---|---|---|
client_id* | string | Unique client identifier. |
client_secret* | string | Client secret string. |
redirect_uri* | string | Specifies the same redirect_uri used in the authorisation request. |
grant_type* | string | Defines the grant type for the request. Possible value are:
|
code* | string | Decoded authorisation code received in the last step. Note: Pass this parameter only when grant_type is 'authorization_code' |
mode | string | The type of mode. Possible values:
|
Response:
{
"public_token": "rzp_test_oauth_8xu1rkZqiXlClS",
"token_type": "Bearer",
"expires_in": 7862400,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IkVhZzBjYmNlMWE3ZTZkIn0.eyJhdWQiOiIzN2pPS3pWZlpqY2hhZ3YiLCJqdGkiOiJFYWcwY2JjZTFhN2U2ZCIsImlhdCI6MTY0NDU3NDAwOSwibmJmIjoxNjQ0NTc0MDA5LCJzdWIiOiJkZXZpY2VzIiwiZXhwIjoxNjQ0NTc3NjA5LCJ1c2VyX2lkIjoiZWRnZWxpc3QiLCJtZXJjaGFudF9pZCI6ImF0bGFzc2V0cyIsInNjb3BlcyI6WyJyZWFkX3VzZXIiXX0.VdE91z_Tm6MABosdSoswqZ2F7-e9QrCQL7Zy24UOnNhe2Y-5y8TGHoTcz5sfe5RvAHHtFv2vyLJ8sXs8foQj2I4pWbWjWSzID9C_RphW7M0M-8-tVd7bEDmwR3fbhAXS4VgQXNIsAmpfPHUXg-QhDqCnpNwLnv1BKrP94wtK85j2",
"refresh_token": "6J7bVX5Ry8brnQ4sV7zA2dW8cP6aX3eW2cV3sZ4rT8dX9eP4yG7hC4jD6dN5fT9qG4tV7bV4cR5gY6rT7eR2hC3nE4tW3yB9bV3bE2cR6cP6fT5fT9kG5yG6qG4dP6aX3dN5yG7dW8gN5cP6gM6yG7rQ4eX9rT8jD6dM6hC4bV3bE2cR5gY6rT7eR2hC3nE4tW3yB9bV3bE2cR6cP6fT5fT9kG5yG6qG4dP6aX3dN5yG7dW8gN5cP6gM6yG7rQ4eX9rT8",
"razorpay_account_id": "acc_Dhk2qDbmu6FwZH"
}
JSONObject refreshTokenRequest = new JSONObject();
refreshTokenRequest.Add("client_id","<YOUR_CLIENT_ID>");
refreshTokenRequest.Add("client_secret","<YOUR_CLIENT_SECRET>");
refreshTokenRequest.Add("refresh_token","J7bVX5Ry8brnQ4sV7zA2dW8cP6aX3eW2cV3sZ4rT8dX");
OAuthTokenClient oAuthTokenClient = oAuth.RefreshToken(refreshTokenRequest);
Parameters:
Name | Type | Description |
---|---|---|
client_id* | string | Unique client identifier. |
client_secret* | string | Client secret string. |
refresh_token* | string | The previously-stored refresh token value. |
Response:
{
"public_token": "rzp_test_oauth_9xu1rkZqoXlClS",
"token_type": "Bearer",
"expires_in": 7862400,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijl4dTF",
"refresh_token": "def5020096e1c470c901d34cd60fa53abdaf36620e823ffa53"
}
JSONObject revokeTokenRequest = new JSONObject();
revokeTokenRequest.Add("client_id","<YOUR_CLIENT_ID>");
revokeTokenRequest.Add("client_secret","<YOUR_CLIENT_SECRET>");
revokeTokenRequest.Add("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IkVhZzBjYmNlMWE3ZTZkIn0.eyJhdWQiOiIzN2pPS3pWZlpqY2hhZ3YiLCJqdGkiOiJFYWcwY2JjZTFhN2U2ZCIsImlhdCI6MTY0NDU3NDAwOSwibmJmIjoxNjQ0NTc0MDA5LCJzdWIiOiJkZXZpY2VzIiwiZXhwIjoxNjQ0NTc3NjA5LCJ1c2VyX2lkIjoiZWRnZWxpc3QiLCJtZXJjaGFudF9pZCI6ImF0bGFzc2V0cyIsInNjb3BlcyI6WyJyZWFkX3VzZXIiXX0.VdE91z_Tm6MABosdSoswqZ2F7-e9QrCQL7Zy24UOnNhe2Y-5y8TGHoTcz5sfe5RvAHHtFv2vyLJ8sXs8foQj2I4pWbWjWSzID9C_RphW7M0M-8-tVd7bEDmwR3fbhAXS4VgQXNIsAmpfPHUXg-QhDqCnpNwLnv1BKrP94wtK85j2");
revokeTokenRequest.Add("token_type_hint","access_token");
OAuthTokenClient oAuthTokenClient = oAuth.RevokeToken(revokeTokenRequest);
Parameters:
Name | Type | Description |
---|---|---|
client_id* | string | Unique client identifier. |
client_secret* | string | Client secret string. |
token_type_hint* | string | The type of token for the request. Possible values:
|
token* | string | The token whose access should be revoked. |
Response:
{
"message": "Token Revoked"
}
PN: * indicates mandatory fields
For reference click here