cross server怎么取出自定义头部的Token
cross server怎么取出自定义头部的Token
客户端是这样发送post请求的
with vHttp do
begin
ContentType := 'application/json';
UserAgent := 'Embarcadero URI Client/1.0';
vHttp.CustomHeaders['Authorization'] := 'Bearer '+'aaaaaaaaaaaaabbbbbbbbbbbcccccccccc';//Access_Token;
服务端这么取token:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | class function TNetCrossMiddleware.AuthenticateDigest( AAuthGetPasswordProc: TAuthGetPasswordProc; const ARealm: string ): TCrossHttpRouterProc2; begin Result := procedure( const ARequest: ICrossHttpRequest; const AResponse: ICrossHttpResponse; var AHandled: Boolean) var LUserName, LCorrectPassword: string ; LNonce, LUserResponse, LCorrectResponse: string ; LAuthStr: string ; A1, A2, HA1, HA2: string ; LAuthParams: TDelimitParams; begin // Authorization: Digest username="admin", realm="test realm", nonce="2468217498b46028705d401192459edd", uri="/login?key=value1", response="1d663058353e8f5831328728c29a6a1a", qop=auth, nc=00000006, cnonce="5d63a594e16feba2" LAuthStr := ARequest.Header[ 'Authorization' ]; if (LAuthStr <> '' ) then begin if (LAuthStr.StartsWith( 'Digest' )) then LAuthStr := LAuthStr.Substring(7) else LAuthStr := '' ; end; LCorrectPassword := #0; if (LAuthStr <> '' ) then begin LAuthParams := TDelimitParams.Create; try LAuthParams.Delimiter := ',' ; LAuthParams.Decode(LAuthStr); LUserName := LAuthParams[ 'username' ].Replace( '"' , '' ); // 获取用户名对应的正确密码 if Assigned(AAuthGetPasswordProc) then AAuthGetPasswordProc(ARequest, LUserName, LCorrectPassword); {$region '计算摘要' } A1 := Format( '%s:%s:%s' , [LUserName, ARealm, LCorrectPassword]); A2 := Format( '%s:%s' , [ARequest.Method, LAuthParams[ 'uri' ].Replace( '"' , '' )]); HA1 := TUtils.BytesToHex(THashMD5.GetHashBytes(A1)); HA2 := TUtils.BytesToHex(THashMD5.GetHashBytes(A2)); LCorrectResponse := HA1 + ':' + LAuthParams[ 'nonce' ].Replace( '"' , '' ) + ':' + LAuthParams[ 'nc' ].Replace( '"' , '' ) + ':' + LAuthParams[ 'cnonce' ].Replace( '"' , '' ) + ':auth' + ':' + HA2; LCorrectResponse := TUtils.BytesToHex(THashMD5.GetHashBytes(LCorrectResponse)); {$endregion} // 客户端已计算好的摘要 LUserResponse := LAuthParams[ 'response' ].Replace( '"' , '' ); finally FreeAndNil(LAuthParams); end; end; // 比对客户端与服务端的摘要是否匹配 if (LAuthStr = '' ) or (LUserResponse <> LCorrectResponse) then begin AHandled := True; LNonce := TUtils.BytesToHex(THashMD5.GetHashBytes(DateTimeToStr(Now))); AResponse.Header[ 'WWW-authenticate' ] := Format( 'Digest realm="%s", qop=auth, nonce="%s"' , [ARealm, LNonce]); AResponse.SendStatus(401); Exit; end; AHandled := False; end; end; |
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/13951970.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2019-11-10 BASE64使用场景
2016-11-10 咏南IOCP中间件支持海量并发方案(集群)