Apigee如何设置使用外部身份验证服务器?
创始人
2024-09-07 17:00:52
0
  1. 在 Apigee 控制台中创建一个具有必要权限的 API 代理。
  2. 选择“流”选项卡,然后单击“编码”选项卡,在“Request” 事件中添加以下代码:

var externalAuthServer = "http://external-auth-server.com/"

if(request.headers.get("Authorization") == null) { response.statusCode = parseInt("401", 10); response.reasonPhrase = "Unauthorized"; response.content = "Authorization header is required."; } else { // Call the external authentication server // Send the Authorization header to the external server curlRequest = new Request(externalAuthServer+"authenticate"); curlRequest.method = "POST"; curlRequest.setHeader("Authorization", request.headers.get("Authorization"));

response = httpClient.send(curlRequest);
if(response.status == parseInt("200", 10)) {
	// At this point, the user is authenticated
	// and you can proceed to the target URL.
            // For instance, if you want to call 
            // a protected API proxy on Apigee 
            // called "my-protected-api", then:

	var targetUrl = "http://my-org.apigee.net/my-protected-api" +
                            request.getUri().getQuery();
            
	targetRequest = new Request(targetUrl);
	targetResponse =  targetHttpClient.send(targetRequest);

} else {
	// Authentication failed. 
	// Set appropriate error codes and error messages.
	response.statusCode = parseInt("401", 10);
       	response.reasonPhrase = "Unauthorized";
       	response.content = "Authentication failed.";
}

}

  1. 在您的外部身份验证服务器上添加“authenticate”端点,该端点接受带有 Authorization 标头的 POST 请求,并验证该标头中的凭据。
  2. 检查 Apigee 代理的“Target Endpoint”配置,确保您的代理使用的是后端使用相同身份验证机制的 API。

请注意,这只是一个示例,可以根据您的身份验证服务器和代理的需求进行定制。

相关内容

热门资讯

今日头条!微信老友广东辅助器,... 今日头条!微信老友广东辅助器,微乐福建辅助器,安装教程(原来有开挂辅助器)是一款可以让一直输的玩家,...
每日必看推荐!微信小程序家乡大... 每日必看推荐!微信小程序家乡大二辅助工具,新西游辅助器,透视教程(原来有开挂辅助安装);1、选手技艺...
玩家亲测!广东插件智能插件安装... 玩家亲测!广东插件智能插件安装包免费,wepoker轻量版有透视吗,详细教程(原来有开挂辅助挂);广...
重大通报!哈糖大菠萝开挂,we... 重大通报!哈糖大菠萝开挂,we-poker是什么软件,解密教程(原来有开挂辅助助手);1.哈糖大菠萝...
解密关于!鱼乐达人辅助修改器,... 解密关于!鱼乐达人辅助修改器,下载微乐小程序自建房透视,介绍教程(原来有开挂辅助软件);解密关于!鱼...
重大发现!四川家园游戏辅助,微... 重大发现!四川家园游戏辅助,微乐自建房辅助多少钱一个月,AI教程(原来有开挂辅助器);微乐自建房辅助...
玩家必用!玉海楼茶苑怎么开挂,... 玩家必用!玉海楼茶苑怎么开挂,天酷互娱有辅助工具嘛,黑科技教程(原来有开挂辅助插件);天酷互娱有辅助...
一分钟教你!椰岛常胜游戏破解,... 一分钟教你!椰岛常胜游戏破解,广东雀神透视,解密教程(原来有开挂辅助下载);椰岛常胜游戏破解软件透明...
实测发现!三江互娱辅助,wpk... 实测发现!三江互娱辅助,wpk显示有透视挂,详细教程(原来有开挂辅助助手),三江互娱辅助是用手机号来...
程序员教你!长春科乐第三方辅助... 程序员教你!长春科乐第三方辅助工具,wepoker代打辅助机器人,曝光教程(原来有开挂辅助黑科技);...