2019-12-17 23:36:07 +01:00
|
|
|
from buildbot.www.oauth2 import OAuth2Auth
|
2019-12-18 19:43:48 +01:00
|
|
|
from urllib.parse import urljoin
|
2019-12-17 23:36:07 +01:00
|
|
|
|
2019-12-20 10:44:16 +01:00
|
|
|
|
2019-12-17 23:36:07 +01:00
|
|
|
class GiteaAuth(OAuth2Auth):
|
|
|
|
name = 'Gitea'
|
|
|
|
faIcon = 'mug-tea'
|
|
|
|
|
2019-12-20 10:44:16 +01:00
|
|
|
AUTH_URL = 'login/oauth/authorize'
|
|
|
|
TOKEN_URL = 'login/oauth/access_token'
|
|
|
|
|
2022-01-23 21:35:21 +01:00
|
|
|
def __init__(self, endpoint, client_id, client_secret, **kwargs):
|
|
|
|
super(GiteaAuth, self).__init__(client_id, client_secret, **kwargs)
|
2019-12-17 23:36:07 +01:00
|
|
|
self.resourceEndpoint = endpoint
|
2019-12-20 10:44:16 +01:00
|
|
|
self.authUri = urljoin(endpoint, self.AUTH_URL)
|
|
|
|
self.tokenUri = urljoin(endpoint, self.TOKEN_URL)
|
2019-12-17 23:36:07 +01:00
|
|
|
|
|
|
|
def getUserInfoFromOAuthClient(self, c):
|
2019-12-20 10:44:16 +01:00
|
|
|
return self.get(c, '/api/v1/user')
|