Example #1
0
    def get_access_token(cls, session_code, **options):
        remote_url = options.get('remote_url',
                                 GITHUB_REMOTE_URL.get()).strip('/')
        client_id = options.get('client_id', GITHUB_CLIENT_ID.get())
        client_secret = options.get('client_secret',
                                    GITHUB_CLIENT_SECRET.get())

        try:
            client = HttpClient(remote_url, logger=LOG)
            root = resource.Resource(client)
            data = {
                'client_id': client_id,
                'client_secret': client_secret,
                'code': session_code
            }
            headers = {
                'content-type': 'application/json',
                'Accept': 'application/json'
            }
            response = root.post('login/oauth/access_token',
                                 headers=headers,
                                 data=json.dumps(data))
            result = cls._get_json(response)
            return result['access_token']
        except RestException, e:
            raise GithubClientException(
                'Failed to request access token from GitHub: %s' % e)
Example #2
0
 def get_authorization_url(cls, **options):
   """
   https://developer.github.com/guides/basics-of-authentication/
   """
   remote_url = options.get('remote_url', GITHUB_REMOTE_URL.get()).strip('/')
   client_id = options.get('client_id', GITHUB_CLIENT_ID.get())
   scopes_list = options.get('scopes_list', cls.DEFAULT_SCOPES)
   scopes = ','.join(scopes_list)
   return '%s/login/oauth/authorize?scope=%s&client_id=%s' % (remote_url, scopes, client_id)
Example #3
0
 def get_authorization_url(cls, **options):
     """
 https://developer.github.com/guides/basics-of-authentication/
 """
     remote_url = options.get('remote_url',
                              GITHUB_REMOTE_URL.get()).strip('/')
     client_id = options.get('client_id', GITHUB_CLIENT_ID.get())
     scopes_list = options.get('scopes_list', cls.DEFAULT_SCOPES)
     scopes = ','.join(scopes_list)
     return '%s/login/oauth/authorize?scope=%s&client_id=%s' % (
         remote_url, scopes, client_id)
Example #4
0
  def __init__(self, **options):
    self._github_base_url = options.get('remote_url', GITHUB_REMOTE_URL.get()).strip('/')
    self._api_url = options.get('api_url', GITHUB_API_URL.get()).strip('/')

    self._client = HttpClient(self._api_url, logger=LOG)
    self._root = resource.Resource(self._client)

    self.__headers = {}
    access_token = options.get('access_token')
    if access_token:
      self.__headers['Authorization'] = 'token %s' % access_token
      # TODO: Redact access_token from logs
    self.__params = ()
Example #5
0
    def __init__(self, **options):
        self._github_base_url = options.get('remote_url',
                                            GITHUB_REMOTE_URL.get()).strip('/')
        self._api_url = options.get('api_url', GITHUB_API_URL.get()).strip('/')

        self._client = HttpClient(self._api_url, logger=LOG)
        self._root = resource.Resource(self._client)

        self.__headers = {}
        access_token = options.get('access_token')
        if access_token:
            self.__headers['Authorization'] = 'token %s' % access_token
            # TODO: Redact access_token from logs
        self.__params = ()
Example #6
0
  def get_access_token(cls, session_code, **options):
    remote_url = options.get('remote_url', GITHUB_REMOTE_URL.get()).strip('/')
    client_id = options.get('client_id', GITHUB_CLIENT_ID.get())
    client_secret = options.get('client_secret', GITHUB_CLIENT_SECRET.get())

    try:
      client = HttpClient(remote_url, logger=LOG)
      root = resource.Resource(client)
      data = {
        'client_id': client_id,
        'client_secret': client_secret,
        'code': session_code
      }
      headers = {
        'content-type':'application/json',
        'Accept': 'application/json'
      }
      response = root.post('login/oauth/access_token', headers=headers, data=json.dumps(data))
      result = cls._get_json(response)
      return result['access_token']
    except RestException, e:
      raise GithubClientException('Failed to request access token from GitHub: %s' % e)