Sry for reviving this old thread, but since there is next to no documentation on this, and google brought me to this thread, I think I should share my knowledge so others who have the same problem don’t need to spend hours reading sourcecode to figure this out.
Basically you need to create an authentication source in the administration. Pick OAuth2 as type and name it gitlab (this is very important!); pick as provider also “GitLab”. Fill in clientID and secret of your Oauth application you created in gitlab (see below) and also check “Use Custom URLs”.
Fill in these:
Now to the gitlab side: Go into user>Apllications (or inside the Admin panel>Applications) and create an new OAuth application. Name it like you want; As redirection url you put https://<your gitea domain>/user/oauth2/gitlab/callback.
No clue what exact scopes it really needs but it definitivly works with these settings:
Trusted: Yes
Confidential: Yes
Scopes:
read_api
read_user
profile
email
Save it and copy the clientID and secret over to gitea as mentioned above.
Now the part I’ve (and most others I belive) got really stuck: you need to logout. When going to the login site, you now have an gitlab icon. Click it, you well get redirected to your gitlab account (if not set to trusted, you might need to approve the application or input 2FA or similar thinks), after that you get redirected back to gitea to be greetet by another dialog: you now kan choose if you want to create an account or login to an existing account. If you login using your account it will link your gitlab to your gitea. It also should run an task in the background to update all old references to your gitlab account with your gitea user. If not: go into the administraion setting, Monitoring and execute the cron task “Update migration poster IDs”. This will also trigger the code to update the old id’s.
Note: 1.16.7 has seemingly a bug where oauth currently dosnt work as intended (500 after beeing redirected back to gitea from gitlab), but in the master branch it works definitvely.