|
| 1 | +### OAuthToken |
| 2 | + |
| 3 | +```rb |
| 4 | +require "razorpay" |
| 5 | +``` |
| 6 | + |
| 7 | +### Generate Authorize Url |
| 8 | +```rb |
| 9 | +body = { |
| 10 | + submerchant_id: '<SUBMERCHANT_MID>', |
| 11 | + timestamp: Time.now.to_i |
| 12 | +} |
| 13 | +onboarding_signature = Razorpay::Utility.generate_onboarding_signature(body, '<YOUR_CLIENT_SECRET>') |
| 14 | + |
| 15 | +options = { |
| 16 | + 'client_id' => '<YOUR_CLIENT_ID>', |
| 17 | + 'redirect_uri' => 'https://example.com/razorpay_callback', |
| 18 | + 'scopes' => ["read_write"], |
| 19 | + 'state' => 'NOBYtv8r6c75ex6WZ', |
| 20 | + 'onboarding_signature' => onboarding_signature |
| 21 | +} |
| 22 | +authorize_url = Razorpay::OAuthToken.get_auth_url(options) |
| 23 | +``` |
| 24 | + |
| 25 | +**Parameters:** |
| 26 | + |
| 27 | +| Name | Type | Description | |
| 28 | +|----------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 29 | +| client_id* | string | Unique client identifier. | |
| 30 | +| 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'. | |
| 31 | +| scopes* | array | Defines what access your application is requesting from the user. You can request one or multiple scopes by adding them to an array as indicated above. | |
| 32 | +| state* | string | A random string generated by your service. This parameter helps prevent cross-site request forgery (CSRF) attacks. | |
| 33 | +| 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 | |
| 34 | + |
| 35 | +**Response:** |
| 36 | +``` |
| 37 | +"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>" |
| 38 | +``` |
| 39 | + |
| 40 | +------------------------------------------------------------------------------------------------------- |
| 41 | +### Get Access token |
| 42 | +```rb |
| 43 | +options = { |
| 44 | + 'client_id' => '<YOUR_CLIENT_ID>', |
| 45 | + 'client_secret' => '<YOUR_CLIENT_SECRET>', |
| 46 | + 'redirect_uri' => 'https://example.com/razorpay_callback', |
| 47 | + 'grant_type' => 'authorization_code', |
| 48 | + 'code' => '<AUTHORIZATION_CODE>', |
| 49 | + 'mode' => 'test' |
| 50 | +} |
| 51 | +oauth_token = Razorpay::OAuthToken.get_access_token(options) |
| 52 | +``` |
| 53 | + |
| 54 | +**Parameters:** |
| 55 | + |
| 56 | +| Name | Type | Description | |
| 57 | +|----------------|--------|------------------------------------------------------------------------------------------------------------------------------| |
| 58 | +| client_id* | string | Unique client identifier. | |
| 59 | +| client_secret* | string | Client secret string. | |
| 60 | +| redirect_uri* | string | Specifies the same redirect_uri used in the authorisation request. | |
| 61 | +| grant_type* | string | Defines the grant type for the request. Possible value are:<ul><li>authorization_code</li><li>client_credentials</li></ul> | |
| 62 | +| code* | string | Decoded authorisation code received in the last step. Note: Pass this parameter only when grant_type is 'authorization_code' | |
| 63 | +| mode | string | The type of mode. Possible values: <ul><li>test</li><li>live (default)</li></ul> | |
| 64 | + |
| 65 | +**Response:** |
| 66 | +```json |
| 67 | +{ |
| 68 | + "public_token": "rzp_test_oauth_9xu1rkZqoXlClS", |
| 69 | + "token_type": "Bearer", |
| 70 | + "expires_in": 7862400, |
| 71 | + "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IkY1Z0NQYkhhRzRjcUpnIn0.eyJhdWQiOiJGNFNNeEgxanMxbkpPZiIsImp0aSI6IkY1Z0NQYkhhRzRjcUpnIiwiaWF0IjoxNTkyODMxMDExLCJuYmYiOjE1OTI4MzEwMTEsInN1YiI6IiIsImV4cCI6MTYwMDc3OTgxMSwidXNlcl9pZCI6IkYycVBpejJEdzRPRVFwIiwibWVyY2hhbnRfaWQiOiJGMnFQaVZ3N0lNV01GSyIsInNjb3BlcyI6WyJyZWFkX29ubHkiXX0.Wwqt5czhoWpVzP5_aoiymKXoGj-ydo-4A_X2jf_7rrSvk4pXdqzbA5BMrHxPdPbeFQWV6vsnsgbf99Q3g-W4kalHyH67LfAzc3qnJ-mkYDkFY93tkeG-MCco6GJW-Jm8xhaV9EPUak7z9J9jcdluu9rNXYMtd5qxD8auyRYhEgs", |
| 72 | + "refresh_token": "def50200f42e07aded65a323f6c53181d802cc797b62cc5e78dd8038d6dff253e5877da9ad32f463a4da0ad895e3de298cbce40e162202170e763754122a6cb97910a1f58e2378ee3492dc295e1525009cccc45635308cce8575bdf373606c453ebb5eb2bec062ca197ac23810cf9d6cf31fbb9fcf5b7d4de9bf524c89a4aa90599b0151c9e4e2fa08acb6d2fe17f30a6cfecdfd671f090787e821f844e5d36f5eacb7dfb33d91e83b18216ad0ebeba2bef7721e10d436c3984daafd8654ed881c581d6be0bdc9ebfaee0dc5f9374d7184d60aae5aa85385690220690e21bc93209fb8a8cc25a6abf1108d8277f7c3d38217b47744d7", |
| 73 | + "razorpay_account_id": "acc_Dhk2qDbmu6FwZH" |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +------------------------------------------------------------------------------------------------------- |
| 78 | + |
| 79 | +### Get Access token using refresh token |
| 80 | +```rb |
| 81 | +options = { |
| 82 | + 'client_id' => '<YOUR_CLIENT_ID>', |
| 83 | + 'client_secret' => '<YOUR_CLIENT_SECRET>', |
| 84 | + 'refresh_token' => 'def5020096e1c470c901d34cd60fa53abdaf3662sa0' |
| 85 | +} |
| 86 | +oauth_token = Razorpay::OAuthToken.refresh_token(options) |
| 87 | +``` |
| 88 | + |
| 89 | +**Parameters:** |
| 90 | + |
| 91 | +| Name | Type | Description | |
| 92 | +|----------------|-----------|--------------------------------------------| |
| 93 | +| client_id* | string | Unique client identifier. | |
| 94 | +| client_secret* | string | Client secret string. | |
| 95 | +| refresh_token* | string | The previously-stored refresh token value. | |
| 96 | + |
| 97 | +**Response:** |
| 98 | +```json |
| 99 | +{ |
| 100 | + "public_token": "rzp_test_oauth_9xu1rkZqoXlClS", |
| 101 | + "token_type": "Bearer", |
| 102 | + "expires_in": 7862400, |
| 103 | + "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijl4dTF", |
| 104 | + "refresh_token": "def5020096e1c470c901d34cd60fa53abdaf36620e823ffa53" |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +------------------------------------------------------------------------------------------------------- |
| 109 | + |
| 110 | +### Revoke a token |
| 111 | +```rb |
| 112 | +options = { |
| 113 | + 'client_id' => '<YOUR_CLIENT_ID>', |
| 114 | + 'client_secret' => '<YOUR_CLIENT_SECRET>', |
| 115 | + 'token' => 'def5020096e1c470c901d34cd60fa53abdaf36620e823ffa53' |
| 116 | + 'token_type_hint' => 'access_token' |
| 117 | +} |
| 118 | +response = Razorpay::OAuthToken.revoke_token(options) |
| 119 | +``` |
| 120 | + |
| 121 | +**Parameters:** |
| 122 | + |
| 123 | +| Name | Type | Description | |
| 124 | +|------------------|----------|----------------------------------------------------------------------------------------------------------| |
| 125 | +| client_id* | string | Unique client identifier. | |
| 126 | +| client_secret* | string | Client secret string. | |
| 127 | +| token_type_hint* | string | The type of token for the request. Possible values: <ul><li>access_token</li><li>refresh_token</li></ul> | |
| 128 | +| token* | string | The token whose access should be revoked. | |
| 129 | + |
| 130 | +**Response:** |
| 131 | +```json |
| 132 | +{ |
| 133 | + "message": "Token Revoked" |
| 134 | +} |
| 135 | +``` |
| 136 | +------------------------------------------------------------------------------------------------------- |
| 137 | + |
| 138 | +**PN: * indicates mandatory fields** |
| 139 | +<br> |
| 140 | +<br> |
| 141 | +**For reference click [here](https://razorpay.com/docs/partners/platform/onboard-businesses/integrate-oauth/integration-steps)** |
| 142 | + |
0 commit comments