Authorizes a user by OAuth2 to get access token
12548
def auth_oauth2(self) -> dict:
        
        oauth_data = {
            'client_id': self._app_id,
            'display': 'mobile',
            'response_type': 'token',
            'scope': '+66560',
            'v': self.API_VERSION
        }
        response = self.post(self.OAUTH_URL, oauth_data)
        url_params = get_url_params(response.url, fragment=True)
        if 'access_token' in url_params:
            return url_params

        action_url = get_base_url(response.text)
        if action_url:
            response = self.get(action_url)
            return get_url_params(response.url)

        response_json = response.json()
        if 'error' in response_json['error']:
            exception_msg = '{}: {}'.format(response_json['error'],
                                            response_json['error_description'])
            raise VVKAuthException(exception_msg)
325687
async def generate_access_token(self, user):
        
        payload = await self._get_payload(user)
        secret = self._get_secret(True)
        algorithm = self._get_algorithm()

        return jwt.encode(payload, secret, algorithm=algorithm).decode("utf-8")
1050017
function authenticate(req, cb) {
    request.post(
      'https://github.com/login/oauth/access_token',
      { form:
        { client_id: process.env.GHID,      // don't store credentials in opts
          client_secret: process.env.GHCS,  // get them straight from process.env
          code: req.query.code } },
      function(err, resp, body) {
        if (err) return cb(err);
        var result = qs.parse(body);
        getUser(req, result, function() {
          cb(null, result);
        });
      }
    );
  }
1260723
def get_access_token(self, verifier=None):
        
        try:
            url = self._get_oauth_url('access_token')
            self.oauth = OAuth1Session(self.consumer_key,
                                       client_secret=self.consumer_secret,
                                       resource_owner_key=self.request_token['oauth_token'],
                                       resource_owner_secret=self.request_token['oauth_token_secret'],
                                       verifier=verifier, callback_uri=self.callback)
            resp = self.oauth.fetch_access_token(url)
            self.access_token = resp['oauth_token']
            self.access_token_secret = resp['oauth_token_secret']
            return self.access_token, self.access_token_secret
        except Exception as e:
            raise TweepError(e)
985876
def access_token(self):
        """"""
        if self.user_id:
            return RemoteToken.get(
                self.user_id, self.remote.consumer_key
            ).access_token
        return self.remote.get_request_token()[0]
1124519
def request_access_token(self, params):
        
        return self.request(self.access_token_url, method="GET", params=params)
1318029
def obtain_access_token(self):
        
        if self.oauth_version != 2:
            raise TwythonError('This method can only be called when your \
                               OAuth version is 2.0.')

        data = {'grant_type': 'client_credentials'}
        basic_auth = HTTPBasicAuth(self.app_key, self.app_secret)
        try:
            response = self.client.post(self.request_token_url,
                                        data=data, auth=basic_auth)
            content = response.content.decode('utf-8')
            try:
                content = content.json()
            except AttributeError:
                content = json.loads(content)
                access_token = content['access_token']
        except (KeyError, ValueError, requests.exceptions.RequestException):
            raise TwythonAuthError('Unable to obtain OAuth 2 access token.')
        else:
            return access_token
549792
def authorize(auth = {})
      auth = @authentication ||= TaskMapper::Authenticator.new(auth)

      if auth[:username].blank? && auth[:email].blank?
        message = "Please provide a username or email."
        raise TaskMapper::Exception.new message
      end

      if auth[:token].blank? && auth[:password].blank?
        message = "Please provide a token or password."
        raise TaskMapper::Exception.new message
      end

      username = (auth[:username].blank? ? auth[:email] : auth[:username])
      password = (auth[:token].blank? ? auth[:password] : auth[:token])

      KanbanpadAPI.authenticate username, password
    end
1203033
def auth(
        cls, consumer_key, redirect_uri='http://example.com/', state=None,
    ):
        '''
        

        '''
        code = cls.get_request_token(consumer_key, redirect_uri, state)

        auth_url = 'https://getpocket.com/auth/authorize?request_token='\
            '%s&redirect_uri=%s' % (code, redirect_uri)
        raw_input(
            'Please open %s in your browser to authorize the app and '
            'press enter:' % auth_url
        )

        return cls.get_access_token(consumer_key, code)
279561
def get_authorization(self, **kwargs):
        """"""
        if self.authorization is not None:
            return self.authorization

        auth_class = self.get_authorization_class()
        auth_user = self.get_authorization_user()
        auth_kwargs = {
            'token': self.get_authorization_token(**kwargs)
        }

        if auth_user and auth_user.is_authenticated():
            auth_kwargs['created_user'] = self.get_authorization_user()

        self.authorization = auth_class.objects.get_by_token_or_404(
            **auth_kwargs
        )
        return self.authorization
1169018
def authorize_url(params = nil)
      return nil if self.token.nil?

      params = (params || {}).merge(:oauth_token => self.token)
      build_authorize_url(consumer.authorize_url, params)
    end
379931
def access_token():
    """"""
    client = Client.query.filter_by(
        client_id=request.form.get('client_id')
    ).first()

    if not client:
        abort(404)

    if not client.is_confidential and \
            'client_credentials' == request.form.get('grant_type'):
        error = InvalidClientError()
        response = jsonify(dict(error.twotuples))
        response.status_code = error.status_code
        abort(response)

    # Return None or a dictionary. Dictionary will be merged with token
    # returned to the client requesting the access token.
    # Response is in application/json
    return None
922998
def request_access_token(self, code, redirect_uri=None):
        '''
        
        '''
        redirect = redirect_uri or self._redirect_uri
        resp_text = _http('POST', 'https://graph.qq.com/oauth2.0/token',
                          client_id=self._client_id, client_secret=self._client_secret,
                          redirect_uri=redirect, code=code, grant_type='authorization_code')
        return self._parse_access_token(resp_text)
638394
def r_oauth_authorized(self):
        
        resp = self.authobj.authorized_response()
        if resp is None:
            return 'Access denied: reason=%s error=%s' % (
                request.args['error'],
                request.args['error_description']
            )
        session['oauth_token'] = (resp['access_token'], '')
        user = self.authobj.get('user')
        ## TODO this is too specific to Perseids' api model. We should externalize.
        session['oauth_user_uri'] = user.data['user']['uri']
        session['oauth_user_name'] = user.data['user']['full_name']
        if 'next' in session and session['next'] is not None:
            return redirect(session['next'])
        else:
            return {
                "template": "nemo_oauth_plugin::authorized.html",
                "username": session['oauth_user_name']
            }
699474
def get_access_token(options = {}, *arguments)
      response = consumer.token_request(consumer.http_method, (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path), self, options, *arguments)
      OAuth::AccessToken.from_hash(consumer, response)
    end
688317
def _do_authorize(self):
        
        if self.auth_data is None:
            raise ApiwatcherClientException("You must provide authorization data.")

        r = requests.post(
            "{0}/api/token".format(self.base_url), json=self.auth_data,
            verify=self.verify_certificate, timeout=self.timeout
        )

        if r.status_code == 401:
            raise ApiwatcherClientException("Wrong credentials supplied: {0}".format(
                r.json()["message"]
            ))
        elif r.status_code != 201:
            try:
                reason = r.json()["message"]
            except:
                reason = r.text
            raise ApiwatcherClientException(
                "Authorization failed. Reason {0} {1}".format(
                    r.status_code, reason)
                )
        else:
            data = r.json()["data"]
            self.token = data["access_token"]

            if "refresh_token" in data:
                self.auth_data = {
                    "grant_type": "refresh_token",
                    "refresh_token": data["refresh_token"],
                    "client_id": self.auth_data["client_id"]
                }
814144
def get_user_token(self, scope, code=None):
        """"""

        user_token = self.__get_user_token(scope)

        if user_token:
            return user_token

        if self.__cache is not None:
            token = self.__cache.get(self.__user_token_cache_key())
            if token:
                return token

        if self.__redirect_uri is None or code is None:
            raise MxitAPIParameterException()

        self.__user_token = None

        payload = {
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': self.__redirect_uri
        }

        url = settings.AUTH_ENDPOINT + '/token'
        r = post(url, data=payload, auth=HTTPBasicAuth(self.__client_id, self.__client_secret), verify=self.__verify_cert)
        if r.status_code == 200:
            data = r.json()
            self.__set_user_token(scope, data[u'access_token'])
            if self.__cache is not None:
                self.__cache.set(self.__user_token_cache_key(scope), str(data[u'access_token']),
                                 data[u'expires_in'] - 300)

        user_token = self.__get_user_token(scope)

        if not user_token:
            raise MxitAPIException("Failed to retrieve user token for '%s' scope" % scope)

        return user_token