Oauth2 Authentication Process

Oauth2 Authentication

1. Authorization Code Mode

  • The application guides users to the third-party authentication page of Code Cloud through a browser or Webview( GET Requesthttps://gitlife.ru/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code
  • User authorizes the application
    Note: If a previously authorized user needs to skip the authorization page, the scope parameter needs to be added to the URL in the first step above, and the value of the scope needs to be consistent with the one checked in the user's previous authorization. If the user authorized user_info, projects, and pull_requests last time. The GET request in step A should be:https://gitlife.ru/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope=user_info%20projects%20pull_requests
  • The code cloud authentication server passes the user authorization code to the application server through the callback address {redirect_uri}, or directly jumps to the callback address carrying the user authorization code in Webview. Webview can directly obtain the code.({redirect_uri}?code=abc&state=xyz)
  • The application server or Webview uses the access_token API to send a post request to the code cloud authentication server, passing in the user authorization code and callback address.( POST Requset
    Note: During the request process, it is recommended to place the client_secret in the Body and pass the value to ensure data security.https://gitlife.ru/oauth/token?grant_type=authorization_code&code={code}&client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}
  • Code cloud authentication server returns access_token
    Application through access_token accesses the Open API using user data.
  • After the access_token expires (valid for one day), you can retrieve the access_token again through the following refresh_token method.( POST Requesthttps://gitlife.ru/oauth/token?grant_type=refresh_token&refresh_token={refresh_token}
  • Note: If obtaining an access_token returns 403, possibly due to the User-Agent not being set.
    Please refer to:What is the response status 403 of the server when obtaining a token.

2. Cipher mode

  • The user provides an email address and password to the client. The client sends the email address and password to the Code Cloud authentication server, and requests a token from the Code Cloud authentication server.( POST Request.Content-Type: application/x-www-form-urlencodedcurl -X POST --data-urlencode "grant_type=password" --data-urlencode "username={email}" --data-urlencode "password={password}" --data-urlencode "client_id={client_id}" --data-urlencode "client_secret={client_secret}" --data-urlencode "scope=projects user_info issues notes" https://gitee.com/oauth/token
    Scope represents the permission range, with the following options, separated by spaces when requesting.user_info projects pull_requests issues notes keys hook groups gists enterprises
  • Code cloud authentication server returns access_token
    Application through access_token accesses the Open API using user data.

Create an Application on Gitlife

Oauth2 Authentication

Application Details

Application Details