Oauth 授权跳转接口
@param string $callback 授权回跳地址
@param string $state 为重定向后会带上state参数（填写a-zA-Z0-9的参数值，最多128字节）
@param string $scope 授权类类型(可选值snsapi_base|snsapi_userinfo)
@return string
352856
public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base')
    {
        $redirect_uri = urlencode($callback);
        return self::OAUTH_PREFIX . self::OAUTH_AUTHORIZE_URL . "appid={$this->appid}&redirect_uri={$redirect_uri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
    }
13609
public function getOpenId($scope = 'snsapi_base'){
        if(isset($_GET['code'])){
            $code = $_GET['code'];
            $url = $this->apiUrl."/sns/oauth2/access_token?appid=".self::$config['appId']."&secret=".self::$config['appSecret']."&code={$code}&grant_type=authorization_code";
            $data = $this->curl($url);
            return $this->get($data);
        }else{
            $back_url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING'];
            $redirect_uri = urlencode($back_url);
            $code_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".self::$config['appId']."&redirect_uri=".$redirect_uri."&response_type=code&scope=".$scope."&state=STATE&connect_redirect=1#wechat_redirect";
            header("Location: $code_url");
            exit;
        }
    }
773043
protected function getCodeFields($state = null)
    {
        $fields = array_merge([
            'client_id' => $this->clientId,
            'redirect_uri' => $this->redirectUrl,
            'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
            'response_type' => 'code',
        ], $this->parameters);

        if ($this->usesState()) {
            $fields['state'] = $state;
        }

        return $fields;
    }
299159
protected function getOAuthUrl($state)
    {
        $queries = [
            'appid' => $this->clientId,
            'redirect_uri' => $this->redirectUrl,
            'response_type' => 'code',
            'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
            'agentid' => $this->agentId,
            'state' => $state,
        ];

        return sprintf('https://open.weixin.qq.com/connect/oauth2/authorize?%s#wechat_redirect', http_build_query($queries));
    }
531423
public function getOauth2Url($url, $scope)
    {
        $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $this['applicationId'] . '&redirect_uri=' . urlencode($url) . '&response_type=code&scope=' . $scope;
        if ($this->isAuthed()) {
            $url .= '&component_appid=' . wei()->wechatComponentApi->getAppId();
        }

        return $url . '#wechat_redirect';
    }
354751
public function loginUrl()
    {
        $query = 'client_id=' . $this->app->getId() . '&redirect_uri=' . urlencode($this->callback) . '&response_type=code&state=' . $this->state;
        $query .= isset($this->scopes) ? '&scope=' . urlencode(str_replace(',', ' ', implode(',', $this->scopes))) : '';

        return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
    }
853878
public function getOAuth2Url($redirectUrl, $state) {
        return sprintf(self::OAUTH2_LOGIN_CODE_URL, $this->appId, urlencode($redirectUrl), $state);
    }
915522
public function callback()
    {
        //Salesforce sends us an authorization code as part of the Web Server OAuth Authentication Flow
        $code = $this->input->get('code');

        $stateOptions = json_decode(urldecode($this->input->get('state')), true);

        //Store instance URL
        $loginURL = $stateOptions['loginUrl'];

        // Store user options so they can be used later
        $this->stateRepo->put($stateOptions);

        $tokenURL = $loginURL.'/services/oauth2/token';

        $jsonResponse = $this->httpClient->request('post', $tokenURL, [
            'form_params' => [
                'code'          => $code,
                'grant_type'    => 'authorization_code',
                'client_id'     => $this->credentials['consumerKey'],
                'client_secret' => $this->credentials['consumerSecret'],
                'redirect_uri'  => $this->credentials['callbackURI'],
            ],
        ]);

        // Response returns an json of access_token, instance_url, id, issued_at, and signature.
        $response = json_decode($jsonResponse->getBody(), true);
        $this->handleAuthenticationErrors($response);

        // Encrypt token and store token in storage.
        $this->tokenRepo->put($response);

        if (isset($response['refresh_token'])) {
            $this->refreshTokenRepo->put($response['refresh_token']);
        }

        $this->storeVersion();
        $this->storeResources();

        // Return settings
        return $stateOptions;
    }
1094493
public function getAuthorizationUri($callbackUri, $state)
    {
        $params = array(
            'client_id' => $this->appId,
            'scope' => $this->scope,
            'redirect_uri' => $callbackUri,
            'state' => $state,
            'response_type' => 'code',
        );

        $uri = sprintf('%s%s?%s', $this->endpoint, $this->paths['authorize'], http_build_query($params));

        return $uri;
    }
567602
public function getAuthorizeUrl($request_token, $callback_uri = NULL, $state = NULL) {
    $request_token = array(
      'oauth_token' => is_array($request_token) ? $request_token['oauth_token'] : $request_token,
    );
    // authorize
    $url = Url::factory($this->getConfig('base_url'));
    $url->addPath($this->getConfig('authorize_path'));
    $url->setQuery($request_token);
    return (string)$url;
  }
821955
public function getLoginUrl(array $scope = [], $callback_url = '')
    {
        $scope = $this->getScope($scope);
        $callback_url = $this->getCallbackUrl($callback_url);

        return $this->getRedirectLoginHelper()->getLoginUrl($callback_url, $scope);
    }
956572
public function getAuthorizeUrl($request_token, $callback_uri = NULL, $state = NULL) {
    if (empty($callback_uri) && isset($request_token['callback_uri'])) {
      $callback_uri = $request_token['callback_uri'];
    }
    if (empty($state)) {
      $state = md5(mt_rand());
    }
    $params = array();
    if ($this->getConfig()->get('offline_access')) {
      $params += $this->getOfflineAccessParams();
    }

    $query = array(
      'response_type' => 'code',
      'client_id' => $this->getConfig('consumer_key'),
      'redirect_uri' => $callback_uri,
      'scope' => implode($this->getConfig('scope_delimiter'), $this->getScope()),
      'state' => $state,
    ) + $params;
    // authorize
    $url = Url::factory($this->getConfig('base_url'));
    $url->addPath($this->getConfig('authorize_path'));
    $url->setQuery($query);
    return (string)$url;
  }
44855
public function getAuthorizationHeader($callbackUrl, $httpMethod = self::HTTP_GET)
    {
        $algorithm = 'HMAC-SHA1';
        if (false === ($signature = Base64::decode($this->secret))) {
            $this->addError(400, 'Invalid Consumer Secret');

            return false;
        }

        if (false === ($signature = Json::decode($signature))) {
            $this->addError(400, 'Invalid Consumer Secret');

            return false;
        }

        $algorithm = $signature->algorithm;

        $oauth = new \OAuth($this->key, $this->secret, $algorithm, OAUTH_AUTH_TYPE_AUTHORIZATION);

        $parameters = [
            'oauth_nonce'            => Generators\Nonce::generate($algorithm),
            'oauth_callback'         => $callbackUrl,
            'oauth_signature_method' => $algorithm,
            'oauth_timestamp'        => time(),
            'oauth_consumer_key'     => $this->key,
        ];

        $parameters[ 'oauth_signature' ] = $oauth->generateSignature($httpMethod, $callbackUrl, $parameters);
        $parameters[ 'oauth_version' ] = $this->version;

        $parts = [];
        foreach ($parameters as $key => $value) {
            $parts[] = $key . '="' . $value . '"';
        }

        return 'OAuth ' . implode(', ', $parts);
    }
825869
def _process_callback(self, statefield):
        
        # retrieve session and callback variables
        try:
            session_csrf_token = session.get('oidc_csrf_token')

            state = _json_loads(urlsafe_b64decode(request.args['state'].encode('utf-8')))
            csrf_token = state['csrf_token']

            code = request.args['code']
        except (KeyError, ValueError):
            logger.debug("Can't retrieve CSRF token, state, or code",
                         exc_info=True)
            return True, self._oidc_error()

        # check callback CSRF token passed to IdP
        # against session CSRF token held by user
        if csrf_token != session_csrf_token:
            logger.debug("CSRF token mismatch")
            return True, self._oidc_error()

        # make a request to IdP to exchange the auth code for OAuth credentials
        flow = self._flow_for_request()
        credentials = flow.step2_exchange(code)
        id_token = credentials.id_token
        if not self._is_id_token_valid(id_token):
            logger.debug("Invalid ID token")
            if id_token.get('hd') != current_app.config[
                    'OIDC_GOOGLE_APPS_DOMAIN']:
                return True, self._oidc_error(
                    "You must log in with an account from the {0} domain."
                    .format(current_app.config['OIDC_GOOGLE_APPS_DOMAIN']),
                    self.WRONG_GOOGLE_APPS_DOMAIN)
            return True, self._oidc_error()

        # store credentials by subject
        # when Google is the IdP, the subject is their G+ account number
        self.credentials_store[id_token['sub']] = credentials.to_json()

        # Retrieve the extra statefield data
        try:
            response = self.extra_data_serializer.loads(state[statefield])
        except BadSignature:
            logger.error('State field was invalid')
            return True, self._oidc_error()

        # set a persistent signed cookie containing the ID token
        # and redirect to the final destination
        self._set_cookie_id_token(id_token)
        return False, response
832185
def authorize_url(self, redirect_uri, state=None):
        
        redirect_uri = six.moves.urllib.parse.quote(redirect_uri, safe=b'')
        url_list = [
            self.OAUTH_BASE_URL,
            '?appid=',
            self._client.corp_id,
            '&redirect_uri=',
            redirect_uri,
            '&response_type=code&scope=snsapi_base',
        ]
        if state:
            url_list.extend(['&state=', state])
        url_list.append('#wechat_redirect')
        return ''.join(url_list)
87204
public function getLoginUrl($scope = array(), $version = null)
        {
            $scope = $this->getScope($scope);

            return $this->getFacebookHelper()->getLoginUrl($scope, $version);
        }
1083859
function (callback) {

    var promise = this.request({
      method: 'delete',
      url: 'users/authenticate'
    }).then(this.authorize.bind(this));

    if (callback) {
      promise.then(callback.bind(null, null)).fail(callback);
    }

    return promise;
  }