身份验证成功后,您可以使用存储为 Cookie 的公共 ID 令牌向 OAuth2 受保护服务器发送请求。
OAuth2 Provider 服务器组件提供多种发送 HTTP 请求的方法:GET、POST、DELETE……
您可以将令牌作为参数传入,或者在使用 Indy 服务器组件时传入 RequestInfo 类。
procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
if ARequestInfo.Document = '/private' then
begin
// return OAuth2 profile data
AResponseInfo.ContentText := OAuth2Provider.Get(ARequestInfo, 'https://graph.microsoft.com/v1.0/me');
AResponseInfo.ContentType := 'application/json';
AResponseInfo.ResponseNo := 200;
end
else
AResponseInfo.ResponseNo := 404;
end;