Gets and stores an OAUTH token from Rightscale.
541784
def login(self):
        
        log.debug('Logging into RightScale...')
        login_data = {
            'grant_type': 'refresh_token',
            'refresh_token': self.refresh_token,
            }
        response = self._request('post', self.oauth_path, data=login_data)

        raw_token = response.json()
        auth_token = "Bearer %s" % raw_token['access_token']
        self.s.headers['Authorization'] = auth_token

        # Generate an expiration time for our token of 60-seconds before the
        # standard time returned by RightScale. This will be used in the
        # self.client property to validate that our token is still usable on
        # every API call.
        log.debug('Auth Token expires in %s(s)' % raw_token['expires_in'])
        self.auth_expires_at = time.time() + int(raw_token['expires_in']) - 60
1225256
def get_authentication_tokens(self):
        
        callback_url = self.callback_url or 'oob'
        request_args = {}
        if OAUTH_LIB_SUPPORTS_CALLBACK:
            request_args['callback_url'] = callback_url

        resp, content = self.client.request(self.request_token_url,
            "GET", **request_args)

        if resp['status'] != '200':
            raise AuthError("Seems something couldn't be verified "\
                "withyour OAuth junk. Error: %s, Message: %s" \
                % (resp['status'], content))

        request_tokens = dict(urlparse.parse_qsl(content))
        oauth_callback_confirmed = request_tokens\
            .get('oauth_callback_confirmed') == 'true'

        if not OAUTH_LIB_SUPPORTS_CALLBACK and callback_url != 'oob'\
            and oauth_callback_confirmed:
            import warnings
            warnings.warn("oauth2 library doesn't support OAuth 1.0a"\
                " type callback, but remote requires it")
            oauth_callback_confirmed = False

        auth_url_params = {'oauth_token': request_tokens['oauth_token']}

        # Use old-style callback argument
        if callback_url != 'oob' and not oauth_callback_confirmed:
            auth_url_params['oauth_callback'] = callback_url

        request_tokens['auth_url'] = self.authenticate_url + '?'\
            + urllib.urlencode(auth_url_params)

        return request_tokens
329357
def _get_auth_token(self):
        
        url = '/%s/oauth2/token' % getattr(
            settings, 'RESTCLIENTS_O365_TENANT', 'test')
        headers = {'Accept': 'application/json'}
        data = {
            "grant_type": "client_credentials",
            "client_id": getattr(settings,
                                 'RESTCLIENTS_O365_CLIENT_ID',
                                 None),
            "client_secret": getattr(settings,
                                     'RESTCLIENTS_O365_CLIENT_SECRET',
                                     None),
            "resource": self._api_host
        }
        body = urlencode(data)
        auth_pool = self._get_pool(self._auth_host)
        response = get_live_url(auth_pool, 'POST', self._auth_host,
                                url, headers=headers, body=body,
                                service_name='o365')
        try:
            json_data = json.loads(response.data)
            if response.status == 200:
                return "%s %s" % (
                    json_data['token_type'], json_data['access_token'])
            else:
                raise DataFailureException(
                    url, response.status,
                    'Auth token failure: %s - %s' % (
                        json_data.get('error', 'unknown'),
                        json_data.get('error_description', 'no description')))
        except ValueError:
            raise DataFailureException(
                url, response.status,
                'Auth token failure: %s' % (response.data))
459723
def _obtain_api_token(self, username, password):
        """"""
        data = self._request("POST", "auth/apitoken",
                             {"username": username, "password": password},
                             reestablish_session=False)
        return data["api_token"]
868057
async def get_request_token(self, loop=None, **params):
        """"""
        params = dict(self.params, **params)
        data = await self.request('GET', self.request_token_url, params=params, loop=loop)

        self.oauth_token = data.get('oauth_token')
        self.oauth_token_secret = data.get('oauth_token_secret')
        return self.oauth_token, self.oauth_token_secret, data
1294518
def get_auth_token(self, user):
        
        data = [str(user.id),
                self.security.hashing_context.hash(encode_string(user._password))]
        return self.security.remember_token_serializer.dumps(data)
181386
function storeToken(token) {
    const file = {
        name: path.join(constants.GLOBAL_DIR, constants.GLOBAL_TOKEN),
        source: JSON.stringify(token),
    };
    createFile(file);
    return;
}
60597
def get_token(self, client_id, target, api_type, grant_type,
                  id_token=None, refresh_token=None, scope='openid'):

        

        if id_token and refresh_token:
            raise ValueError('Only one of id_token or refresh_token '
                             'can be None')

        data = {
            'client_id': client_id,
            'grant_type': grant_type,
            'target': target,
            'scope': scope,
            'api_type': api_type,
        }

        if id_token:
            data.update({'id_token': id_token})
        elif refresh_token:
            data.update({'refresh_token': refresh_token})
        else:
            raise ValueError('Either id_token or refresh_token must '
                             'have a value')

        return self.post(
            'https://{}/delegation'.format(self.domain),
            headers={'Content-Type': 'application/json'},
            data=data
        )
1348313
def request(self, method, url, **kwargs):
        """"""
        user_token = kwargs.pop('token', self.token)
        token, secret, expires_at = self.parse_raw_token(user_token)
        if token is not None:
            params = kwargs.get('params', {})
            params['access_token'] = token
            kwargs['params'] = params
        return super(OAuth2Provider, self).request(method, url, **kwargs)
1325854
def fetch_token(self, **kwargs):
        """"""
        return super(AsanaOAuth2Session, self).fetch_token(self.token_url, client_secret=self.client_secret, **kwargs)
647675
function getAccessToken($oauth_verifier = FALSE)
    {
        $parameters = [];
        if (!empty($oauth_verifier)) {
            $parameters['oauth_verifier'] = $oauth_verifier;
        }
        $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
        $token = OAuthUtil::parse_parameters($request);
        $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
        return $token;
    }
1155681
def access_token(self):
        """"""
        if self.cache_token:
            return self.access_token_ or \
                   self._resolve_credential('access_token')
        return self.access_token_
153119
def store_tokens(self, access_token, id_token):
        """"""
        session = self.request.session

        if self.get_settings('OIDC_STORE_ACCESS_TOKEN', False):
            session['oidc_access_token'] = access_token

        if self.get_settings('OIDC_STORE_ID_TOKEN', False):
            session['oidc_id_token'] = id_token
1370302
def get_access_token(self, code=None, **params):
        
        if self._access_token is None:
            if code is None:
                raise ValueError(_('Invalid code.'))
            
            self.access_token_dict = self._get_access_token(code, **params)
            try:
                self._access_token = self.access_token_dict['access_token']
            except KeyError, e:
                raise OAuthError("Credentials could not be validated, the provider returned no access token.")
                
        return self._access_token
270573
def get_token(request):
    
    if (not request.META.get(header_name_to_django(auth_token_settings.HEADER_NAME)) and
            config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME):
        ovetaker_auth_token = request.COOKIES.get(config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME)
        token = get_object_or_none(Token, key=ovetaker_auth_token, is_active=True)
        if utils.get_user_from_token(token).is_authenticated():
            return token

    return utils.get_token(request)
1116931
@Override
    public OAuthToken get(String envKey) {
        if (!oAuthToken.containsKey(envKey)) return null;
        
        return oAuthToken.get(envKey);
    }
51938
def token(ctx, opts, login, password):
    """"""
    click.echo(
        "Retrieving API token for %(login)s ... "
        % {"login": click.style(login, bold=True)},
        nl=False,
    )

    context_msg = "Failed to retrieve the API token!"
    with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
        with maybe_spinner(opts):
            api_key = get_user_token(login=login, password=password)

    click.secho("OK", fg="green")

    click.echo(
        "Your API key/token is: %(token)s"
        % {"token": click.style(api_key, fg="magenta")}
    )

    create, has_errors = create_config_files(ctx, opts, api_key=api_key)

    if has_errors:
        click.echo()
        click.secho("Oops, please fix the errors and try again!", fg="red")
        return

    if opts.api_key != api_key:
        click.echo()
        if opts.api_key:
            click.secho(
                "Note: The above API key doesn't match what you have in "
                "your default credentials config file.",
                fg="yellow",
            )
        elif not create:
            click.secho(
                "Note: Don't forget to put your API key in a config file, "
                "export it on the environment, or set it via -k.",
                fg="yellow",
            )
            click.secho(
                "If you need more help please see the documentation: "
                "%(website)s" % {"website": click.style(get_help_website(), bold=True)}
            )
        click.echo()

    click.secho("You're ready to rock, let's start automating!", fg="green")