|
| 1 | +# OAuth Token Hashing |
| 2 | + |
| 3 | +WSO2 Identity Server (WSO2 IS) allows you to enable OAuth2 token hashing to protect OAuth2 access tokens, refresh tokens, consumer secrets, and |
| 4 | +authorization codes. |
| 5 | + |
| 6 | +!!! note |
| 7 | + - Token hashing is only required if there are long lived tokens. |
| 8 | + |
| 9 | + - If you want to enable this feature, WSO2 recommends using a fresh |
| 10 | + WSO2 Identity Server distribution. |
| 11 | + |
| 12 | + - To use this feature with an existing database, you may need to |
| 13 | + perform data migration before you enable the feature. If you have to |
| 14 | + perform data migration before you enable this feature, [Contact |
| 15 | + us](https://wso2.com/contact/). |
| 16 | + |
| 17 | +---- |
| 18 | + |
| 19 | +## Set up OAuth token hashing |
| 20 | + |
| 21 | +1. Add the following configurations to the `deployment.toml` file found in the `<IS_HOME>/repository/conf` folder. |
| 22 | + - Add the following property and set it to true to enable hashing. |
| 23 | + |
| 24 | + ``` toml |
| 25 | + [oauth] |
| 26 | + hash_tokens_and_secrets = true |
| 27 | + ``` |
| 28 | + |
| 29 | + - Add the following configuration to specify the algorithm to use for hashing: |
| 30 | + |
| 31 | + ``` toml |
| 32 | + [oauth] |
| 33 | + hash_token_algorithm = "SHA-256" |
| 34 | + ``` |
| 35 | + |
| 36 | + - Add the following token persistence processor to enable token hashing: |
| 37 | + |
| 38 | + ``` toml |
| 39 | + [oauth.extensions] |
| 40 | + token_persistence_processor = "org.wso2.carbon.identity.oauth.tokenprocessor.HashingPersistenceProcessor" |
| 41 | + ``` |
| 42 | + |
| 43 | + !!! tip |
| 44 | + WSO2 Identity Server allows you to use hashing algorithms supported by MessageDigest. For more information on hashing algorithms supported by MessageDigest, see [MessageDigest Algorithms](https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest). |
| 45 | + |
| 46 | + The default algorithm for hashing is SHA-256. |
| 47 | + |
| 48 | +2. Run the appropriate database command to remove the `CONN_APP_KEY` constraint from the `IDN_OAUTH2_ACCESS_TOKEN` table. |
| 49 | + |
| 50 | + For example, if you are using an H2 database, you need to run the following command: |
| 51 | + |
| 52 | + ``` sql |
| 53 | + ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN DROP CONSTRAINT IF EXISTS CON_APP_KEY |
| 54 | + ``` |
| 55 | + |
| 56 | + !!! tip |
| 57 | + In general, for a specified consumer key, user, and scope, there can be only one active access token. The `CON_APP_KEY` constraint in the |
| 58 | + `IDN_OAUTH2_ACCESS_TOKEN` table enforces this by allowing only one active access token to exist for specified consumer key, user, and scope values. |
| 59 | + |
| 60 | + With regard to hashing, a new access token is issued for every access token request. Therefore, for a given consumer key, user, and scope, there can be multiple active access tokens. To allow existence of multiple active access tokens, you need to remove the `CONN_APP_KEY` constraint from the `IDN_OAUTH2_ACCESS_TOKEN` table. |
| 61 | + |
| 62 | +---- |
| 63 | + |
| 64 | +## Configure a service provider |
| 65 | + |
| 66 | +Follow the steps below to register an application: |
| 67 | + |
| 68 | +1. On the {{ product_name }} Console, go to **Applications**. |
| 69 | + |
| 70 | +2. Click **New Application** and select **Standard-Based Application** to open the following: |
| 71 | + |
| 72 | + {: width="600" style="display: block; margin: 0;"} |
| 73 | + |
| 74 | +3. Provide an application name. |
| 75 | + |
| 76 | +4. Select **OAuth 2.0 OpenID Connect** as the application protocol. |
| 77 | + |
| 78 | +5. Click **Register** to complete the registration. |
| 79 | + |
| 80 | +!!! tip |
| 81 | + The **Consumer Secret** value is displayed in plain text only once. Therefore, be sure to copy and save it for later use. |
| 82 | + |
| 83 | +You have successfully set up OAuth token hashing. Now all of the OAuth2 access tokens, refresh tokens, consumer secrets, and authorization codes will be hashed in the database. |
0 commit comments