通过code换取网页授权access_token
@param appid appid
@param secret secret
@param code code
@return SnsToken
506645
public static SnsToken oauth2AccessToken(String appid,String secret,String code){
		HttpUriRequest httpUriRequest = RequestBuilder.post()
				.setUri(BASE_URI + "/sns/oauth2/access_token")
				.addParameter("appid", appid)
				.addParameter("secret", secret)
				.addParameter("code", code)
				.addParameter("grant_type", "authorization_code")
				.build();
		return LocalHttpClient.executeJsonResult(httpUriRequest,SnsToken.class);
	}
750201
def access_token(self, request_token, request_secret):
        """"""
        logging.debug("Getting access token from %s:%d",
                      self.server, self.port)
        self.access_token, self.access_secret = \
            self._token("/oauth/accessToken", request_token, request_secret)
        return self.access_token, self.access_secret
422202
def get_access_token_from_code(
        self, code, redirect_uri, app_id, app_secret
    ):
        
        args = {
            "code": code,
            "redirect_uri": redirect_uri,
            "client_id": app_id,
            "client_secret": app_secret,
        }

        return self.request(
            "{0}/oauth/access_token".format(self.version), args
        )
1205448
UserCredentials fetchUserCredentials( String code )
    {
        HttpPost post = new HttpPost( accessTokenUrl );

        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add( new BasicNameValuePair( OAuth2.CLIENT_ID, appInfo.getAppId() ) );
        parameters.add( new BasicNameValuePair( OAuth2.CLIENT_SECRET, appInfo.getAppSecret() ) );
        parameters.add( new BasicNameValuePair( OAuth2.CODE, code ) );
        parameters.add( new BasicNameValuePair( OAuth2.GRANT_TYPE, OAuth2.AUTHORIZATION_CODE ) );

        if ( appInfo.getRedirectUrl() != null ) {
            parameters.add( new BasicNameValuePair( OAuth2.REDIRECT_URI, appInfo.getRedirectUrl() ) );
        }

        try {
            post.setEntity( new UrlEncodedFormEntity( parameters, PcsUtils.UTF8.name() ) );
        } catch ( UnsupportedEncodingException ex ) {
            throw new CStorageException( "Can't encode parameters", ex );
        }

        HttpResponse response;

        try {
            response = httpClient.execute( post );
        } catch ( IOException e ) {
            throw new CStorageException( "HTTP request while fetching token has failed", e );
        }

        // FIXME check status code here
        final String json;

        try {
            json = EntityUtils.toString( response.getEntity(), PcsUtils.UTF8.name() );
        } catch ( IOException e ) {
            throw new CStorageException( "Can't retrieve json string in HTTP response entity", e );
        }
        LOGGER.debug( "fetchUserCredentials - json: {}", json );

        Credentials credentials = Credentials.createFromJson( json );
        userCredentials = new UserCredentials( appInfo,
                                               null, // userId is unknown yet
                                               credentials );

        return userCredentials;
    }
457644
private HashMap<String, String> createTokenRequestParams(String grantCode) {

        HashMap<String, String> params = new HashMap<>();

        params.put("code", grantCode);
        params.put("client_id", preferences.clientId.get());
        params.put("grant_type", "authorization_code");
        params.put("redirect_uri", HTTP_LOCALHOST);

        return params;
    }
721002
public function setCredentials($appId, $secretKey)
    {
        $this->appId = $appId;
        $this->secretKey = $secretKey;
        return $this;
    }
1142928
function(code, cb) {
        var self = this;
        this.oauthClient.getToken(code, function(err, token) {
            if (err) {
                cb({
                    err: err,
                    msg: 'Error while trying to retrieve access token'
                });
                return;
            }
            self.storeToken(token);
            cb(null, {
                resp: token,
                msg: "Google auth code successfully set"
            });
        });
    }
1052258
public static MnoHttpClient getAuthenticatedClient(String key, String secret, String contentType) {
		MnoHttpClient client = new MnoHttpClient(contentType);
		String authStr = key + ":" + secret;
		client.basicAuthHash = "Basic " + DatatypeConverter.printBase64Binary(authStr.getBytes());

		return client;
	}
193458
public OauthGetTokenResponse getToken(String code) {
        BeanUtil.requireNonNull(code, "code is null");
        OauthGetTokenResponse response = null;
        String url = BASE_API_URL + "sns/oauth2/access_token?appid=" + this.config.getAppid() + "&secret=" + this.config.getSecret() + "&code=" + code + "&grant_type=authorization_code";
        BaseResponse r = executeGet(url);
        String resultJson = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        response = JSONUtil.toBean(resultJson, OauthGetTokenResponse.class);
        return response;
    }
602756
def auth(self, code):
        
        request_data = self.get_access_token_params(code)

        res = self._session.post(**request_data)
        if res.status_code != 200:
            raise APIException(
                request_data['url'],
                res.status_code,
                response=res.content,
                request_param=request_data,
                response_header=res.headers
            )

        json_res = res.json()
        self.update_token(json_res)
        return json_res
237604
def auth(self, code="", refresh_token=""):

        

        if refresh_token:
            try:
                self.oauth.request_token(grant_type="refresh_token", refresh_token=refresh_token)
                self.refresh_token = self.oauth.refresh_token
            except HTTPError as e:

                if e.code == 401:
                    raise DeviantartError("Unauthorized: Please check your credentials (client_id and client_secret).")
                else:
                    raise DeviantartError(e)
        elif self.standard_grant_type == "authorization_code":
            try:
                self.oauth.request_token(grant_type=self.standard_grant_type, redirect_uri=self.redirect_uri, code=code)
                self.refresh_token = self.oauth.refresh_token
            except HTTPError as e:

                if e.code == 401:
                    raise DeviantartError("Unauthorized: Please check your credentials (client_id and client_secret).")
                else:
                    raise DeviantartError(e)
        elif self.standard_grant_type == "client_credentials":
            try:
                self.oauth.request_token(grant_type=self.standard_grant_type)
            except HTTPError as e:

                if e.code == 401:
                    raise DeviantartError("Unauthorized: Please check your credentials (client_id and client_secret).")
                else:
                    raise DeviantartError(e)
        else:
            raise DeviantartError('Unknown grant type.')

        self.access_token = self.oauth.access_token
801429
function getAccessToken($google_code) {
        // Make sure these are clear if we fail
        $this->authentication_object = FALSE;
        $this->access_token = FALSE;

        // From: https://github.com/PenguinProtocols/Basic-OpenID-Connect-Google
        // This approach gets us the openid_id from the former realm

        $token_url = "https://www.googleapis.com/oauth2/v3/token";
        $post = "code={$google_code}&client_id={$this->client_id}&client_secret={$this->client_secret}"
            . "&redirect_uri={$this->redirect}&grant_type=authorization_code";

        if ( $this->openid_realm ) {
            $post .= "&openid.realm=" . $this->openid_realm;
        }

        $response = $this->curl_post($token_url, $post);

        /* $response normally looks like this:
            {
                "access_token" : "QEX3L0Fm ... about 80 characters ... 4tLMYze617",
                "token_type" : "Bearer",
                "expires_in" : 3599,
                "id_token" : "hbGciO ... about 700 characers ... t3cE"
            }
        */

        if ($response) {
            $this->authentication_object = json_decode($response);
        }

        if (isset($this->authentication_object->refresh_token)) {
            $this->Google_RefreshToken = $this->authentication_object->refresh_token;
        }
        if (isset($this->authentication_object->access_token)) {
            $this->access_token = $this->authentication_object->access_token;
            return $this->authentication_object;
        } else {
            return FALSE;
        }
    }
723577
def get_access_token(self, code):
        """"""
        try:
            self._token = super().fetch_token(
                MINUT_TOKEN_URL,
                client_id=self._client_id,
                client_secret=self._client_secret,
                code=code,
            )
        # except Exception as e:
        except MissingTokenError as error:
            _LOGGER.debug("Token issues: %s", error)
        return self._token
592580
public Iterable<DConnection> queryBySecret(java.lang.String secret) {
    return queryByField(null, DConnectionMapper.Field.SECRET.getFieldName(), secret);
  }
1365467
public static String getAccessToken(String clientId, String clientSecret, String code, String redirectUri) {
		RequestBuilder call = new RequestBuilder(GRAPH_ENDPOINT + "oauth/access_token", HttpMethod.GET);
		call.setTimeout(10 * 1000);	// this is a somewhat crude hack but seems reasonable right now
		call.addParam("client_id", clientId);
		call.addParam("client_secret", clientSecret);
		if (code != null || redirectUri != null) {
			call.addParam("code", code);
			call.addParam("redirect_uri", redirectUri);
		} else
			call.addParam("grant_type", "client_credentials");
		
		try {
			HttpResponse response = call.execute();
			
			// Yet more Facebook API stupidity; if the response is OK then we parse as urlencoded params,
			// otherwise we must parse as JSON and run through the error detector.
			if (response.getResponseCode() == 200) {
				return URLParser.parseQuery(StringUtils.read(response.getContentStream())).get("access_token");
			} else {
				Later<JsonNode> json = new Now<JsonNode>(new ObjectMapper().readTree(response.getContentStream()));
				new ErrorDetectingWrapper(json).get();	// This should throw an exception
				throw new IllegalStateException("Impossible, this should have been detected as an error: " + json);
			}
		} catch (IOException ex) {
			throw new IOFacebookException(ex);
		}
	}
1125785
public static PreAuthCode api_create_preauthcode(String component_access_token, String component_appid) {
        String postJsonData = String.format("{\"component_appid\":\"%1$s\"}",
                component_appid);
        HttpUriRequest httpUriRequest = RequestBuilder.post()
                .setHeader(jsonHeader)
                .setUri(BASE_URI + "/cgi-bin/component/api_create_preauthcode")
                .addParameter("component_access_token", API.componentAccessToken(component_access_token))
                .setEntity(new StringEntity(postJsonData, Charset.forName("utf-8")))
                .build();
        return LocalHttpClient.executeJsonResult(httpUriRequest, PreAuthCode.class);
    }
1373643
def get_token(self, code, headers=None, **kwargs):
        
        self._check_configuration("site", "token_url", "redirect_uri",
                                  "client_id", "client_secret")
        url = "%s%s" % (self.site, quote(self.token_url))
        data = {
            'redirect_uri': self.redirect_uri,
            'client_id': self.client_id,
            'client_secret': self.client_secret,
            'code': code,
        }
        data.update(kwargs)

        return self._make_request(url, data=data, headers=headers)