user should go to this link https://${GITLAB_HOST}/oauth/authorize?client_id=${GITLAB_APP_ID}&response_type=code&redirect_uri=${BACKEND_HOST}/${OAUTH_ENDPOINT}
GITLAB_HOST - the host of your gitlab instance, if you dont have, it can be gitlab.com
GITLAB_APP_ID - id of application, which created on GITLAB_HOST
OAUTH_ENDPOINT - backend endpoint to get gitlab oauth code
2. /oauth/token
backend sends request to get access token, to next autorizations. example in python
import requests
from requests import auth
# this u can get in your gitlab > profile > preferences > application
GITLAB_APP_ID = os.environ["GITLAB_APP_ID"]
GITLAB_APP_SECRET = os.environ["GITLAB_APP_SECRET"]
def get_token(code: str):
client_auth = auth.HTTPBasicAuth(GITLAB_APP_ID, GITLAB_APP_SECRET)
post_data = {
"grant_type": "authorization_code",
"code": code,
"redirect_uri": "https://${BACKEND_HOST}/${OAUTH_ENDPOINT}"
}
response = requests.post(
"https://gitlab.com/oauth/token",
auth=client_auth,
data=post_data
)
data = response.json()
return data["access_token"]
Access Token Usage
from gitlab import Gitlab
oauth_access_token = "imagine u got this from previous steps"
gitlab = Gitlab(oauth_token=oauth_access_token)
gitlab.user # this will return current user, the user whos access token we actually got
OAuth Authorization for users
Source
1.
/oauth/authorize
user should go to this link
https://${GITLAB_HOST}/oauth/authorize?client_id=${GITLAB_APP_ID}&response_type=code&redirect_uri=${BACKEND_HOST}/${OAUTH_ENDPOINT}
GITLAB_HOST
- the host of your gitlab instance, if you dont have, it can begitlab.com
GITLAB_APP_ID
- id of application, which created onGITLAB_HOST
OAUTH_ENDPOINT
- backend endpoint to get gitlab oauth code2.
/oauth/token
backend sends request to get access token, to next autorizations. example in python
Access Token Usage