You can enable organization members to authorize your OAuth app.
When you build an OAuth app, implement the web application flow described below to obtain an authorization code and then exchange it for a token.
Вы должны перенаправить пользователя на конечную точку /oauth/authorize со следующими параметрами GET:
This will ask the user to approve the app access to their account based on the scopes specified in REQUESTED_SCOPES and then redirect back to the REDIRECT_URI you provided when creating an app.
Название | Значение | Описание |
---|---|---|
client_id | строка | Необходим. You receive Client ID for the app when you register it. |
redirect_uri | строка | Необходим. The URL in your application where users will be sent after authorization. |
response_type: code | строка | Необходим. The parameter is used for the flow specification of an OAuth app. |
scope | строка | Необходим. Select the access your app requires from the list of scopes available. You can add multiple scopes separated by spaces (no need to use quotation marks). |
state | строка | An unguessable random string. Use it for extra protection against cross-site request forgery attacks. |
Будет создан следующий авторизационный URL:
После успешной авторизации пользователи перенаправляются обратно на ваш сайт:
Если авторизация отклонена, пользователи перенаправляются на ваш сайт с ошибкой:
If a user authorizes the app, Crowdin Enterprise redirects back to your site and you can exchange the code received for an access token:
Название | Значение | Описание |
---|---|---|
grant_type: authorization_code | строка | Необходим. The parameter is used for the flow specification of an OAuth app. |
client_id | строка | Необходим. You receive Client ID for the app when you register it. |
client_secret | строка | Необходим. You receive Client Secret for the app when you register it. |
redirect_uri | строка | Необходим. The URL in your application where users will be sent after authorization. |
code | строка | Необходим. Code received from the callback query string. |
For example, request in curl takes the following form:
curl -X POST \ https://accounts.crowdin.com/oauth/token \ -H "content-type: application/json" \ -d "{ \"grant_type\":\"authorization_code\", \"client_id\":\"m50YenPpqac8u5D4dnK\", \"client_secret\":\"yz35kYtjox...YE9Am\", \"redirect_uri\":\"https://impact-mobile.com/auth/crowdin\", \"code\":\"def50200df1fbb5ebac05f9288850d9e...0835bd3cf42\" }"
По умолчанию ответ принимает следующий вид:
{
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJS...lag1e_Zk4EdJ5diYfz0",
"token_type":"bearer",
"expires_in": 7200,
"refresh_token": "b213c684ccaa7db1217e946e6ad...fff7ae"
}
The access token now allows you to make requests to Crowdin Enterprise API on behalf of the authorized user.
For example, in curl you can set the following Authorization header:
curl -H "Authorization: Bearer ACCESS_TOKEN" https://<organization_domain>.api.crowdin.com/api/v2/projects
The access token received after a user authorizes the app has an expiration time. Access token expires in the number of seconds defined in the response.
To refresh a token without requiring the user to be redirected, send a POST request with the following body parameters to the authorization server:
Название | Значение | Описание |
---|---|---|
grant_type: refresh_token | строка | Необходим. The parameter is used for the flow specification of an OAuth app. |
client_id | строка | Необходим. You receive Client ID for the app when you register it. |
client_secret | строка | Необходим. You receive Client Secret for the app when you register it. |
refresh_token | строка | Необходим. Refresh token received from the last authorization response. |
For example, request in curl takes the following form:
curl -X POST \ https://accounts.crowdin.com/oauth/token \ -H "content-type: application/json" \ -d "{ \"grant_type\":\"refresh_token\", \"client_id\":\"m50YenPpqac8u5D4dnK\", \"client_secret\":\"yz35kYtjox...YE9Am\", \"refresh_token\":\"b213c684ccaa7db1217e946e6ad...fff7ae\" }"
По умолчанию ответ принимает следующий вид:
{
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJS...ZjFkMWI4OWFlIiwiaWF",
"token_type":"bearer",
"expires_in": 7200,
"refresh_token": "ea506ea4c37aa152f0a91ed2482...4a0c567"
}
You can register one or more redirect URLs when you create an OAuth Application on Crowdin Enterprise.
For security reasons, if the URL is not included in the Application info you won’t be able to redirect users to this URL after authorization.