buildbot-transifex/buildbot_gitea/auth.py

20 lines
603 B
Python
Raw Normal View History

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'
2019-12-17 23:36:07 +01:00
def __init__(self, endpoint, client_id, client_secret):
2019-12-20 10:44:16 +01:00
super(GiteaAuth, self).__init__(client_id, client_secret)
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')