跳到主要内容

OAuth Documentation

1. Authentication interface

request

GET https://gitcode.com/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope={scope}&state={state}

Parameter nameDescriptionTypeData type
client_id*Registered client IDquerystring
redirect_uri*URL after authorizationquerystring
scopepermission scopequerystring
stateRandom string,
used to prevent cross-site request forgery attacks
querystring

2. Redirect

If the user accepts your authorization, GitCode will redirect back to your website, carrying the code parameter and the state you provided in the parameter in the previous step. If the status does not match, a third party created the request and the process needs to be aborted.

GET {redirect_uri}?code={code}&state={state}

3. Obtain authorization token

POST https://gitcode.com/oauth/token?grant_type=authorization_code&code={code}&client_id={client_id}&client_secret={client_secret}

Parameter nameDescriptionTypeData type
grant_typeAuthorization code modequeryauthorization_code
code*authorization codequerystring
client_id*Registered client IDquerystring
client_secret*Registered client secretform-datastring

response

{
"access_token": "eyPZPVNfsibj9tap_ibj3t3p",
"expires_in": 1296000,
"refresh_token": "b77ced3aee884348852160deab3697a1",
"scope": "all_user all_key all_groups all_projects all_pr all_issue all_note all_hook all_repository",
"created_at": "2024-04-20T09:07:59.889Z"
}

4. Use access token to access user information API

Authorization: Bearer {access_token}
GET https://api.gitcode.com/api/v5/user

5. Refresh access_token

POST https://gitcode.com/oauth/token?grant_type=refresh_token&refresh_token={refresh_token}

4. 使用访问令牌访问用户信息API

Authorization: Bearer {access_token}
GET https://api.gitcode.com/api/v5/user

5. 刷新access_token

POST https://gitcode.com/oauth/token?grant_type=refresh_token&refresh_token={refresh_token}