xquery version "3.1"; (: : Module Name: XQuery Allegro API Authorization Library Module : : Module Version: 1.0 : : Date: June 26, 2019 : : Copyright: release11.com : : Properietary : Extensions: none : : XQuery : Specification: April 2019 : : Module Overview: This module authorizes an user. :) (:~ : This module authorizes an user and allows acces to Allegro RESTApi with access token. : : @author Tomasz Kaleta : @since June 26, 2019 : @version 1.0 :) module namespace auth="http://release11.com/xquery-allegro-api/authorization"; import module namespace hc="http://expath.org/ns/http-client"; (:~ : This function gets access token from Allegro authorization service. : Token is necessary to authenticate an apllication. : : @param authorizationUrl Allegro OAuth 2.0 authorization endpoint : @param base64credentials base64 encoded client id and client secret joined by ':'. : @return access token. :) declare function auth:get-access-token($authorizationUrl as xs:string, $base64credentials as xs:string) as xs:string { let $accessTokenResponse := hc:send-request( ) return $accessTokenResponse//access__token }; (:~ : This function concats token type and access token. : : @param $accessToken accesToken granted by authorization service. @param $tokenType type of the token required by authorization service. : @return authorization header required to be sent with every request. :) declare function auth:get-authorization-header($accessToken as xs:string, $tokenType as xs:string) as xs:string { string-join(($tokenType, $accessToken), ' ') };