Пример #1
0
        /// <summary>
        /// Releases consumed licenses.
        /// </summary>
        /// <param name="consumptionIds">The consumption ids, as returned in the value of the <c>jti</c> authorization decision field.</param>
        /// <param name="responseType">The <see cref="ResponseType"/> requested from the server, or <c>null</c> for server default.</param>
        /// <returns>List of <see cref="AuthorizationDecision"/> objects representing the authorization decision response from the server.</returns>
        public async Task <IList <AuthorizationDecision> > ReleaseLicensesAsync(IList <string> consumptionIds, ResponseType responseType = null)
        {
            var releaseLicenseUri = BuildReleaseLicenseUri(consumptionIds, responseType);
            var responseData      = await SendAuthorizationRequestAsync(releaseLicenseUri, HttpMethod.Post);

            var responseBody        = responseData.Key;
            var responseContentType = responseData.Value;

            return(AuthorizationDecision.FromServerResponse(consumptionIds, responseBody, responseContentType, AuthzApiConfig.SignerKey));
        }
Пример #2
0
        /// <summary>
        /// Sends a request to the <c>/authz/</c> endpoint for getting authorization decisions. The request
        /// may only check for authorizations, or it may consume licenses.
        /// </summary>
        /// <param name="authorizedItems">Names of the items for which authorization is requested.</param>
        /// <param name="responseType">The <see cref="ResponseType"/> requested from the server, or <c>null</c> for server default.</param>
        /// <param name="consume"><c>true</c> to consume a license, <c>false</c> otherwise.</param>
        /// <param name="consumptionMode">Consumption mode: <see cref="ConsumptionMode.Cache"/> for short-term consumption by online clients,
        /// <returns><see cref="AuthorizationDecision"/> object representing the authorization decision response from the server.</returns>
        public async Task <IList <AuthorizationDecision> > CheckOrConsumeAsync(
            IList <string> authorizedItems,
            bool consume = false,
            ResponseType responseType       = null,
            ConsumptionMode consumptionMode = ConsumptionMode.Cache)
        {
            var authzDecisionRequestUri = BuildCheckOrConsumeUri(
                authorizedItems,
                responseType,
                consume,
                consumptionMode);
            var method       = consume ? HttpMethod.Post : HttpMethod.Get;
            var responseData = await SendAuthorizationRequestAsync(authzDecisionRequestUri, method);

            var responseBody        = responseData.Key;
            var responseContentType = responseData.Value;

            return(AuthorizationDecision.FromServerResponse(authorizedItems, responseBody, responseContentType, AuthzApiConfig.SignerKey));
        }
Пример #3
0
        /// <summary>
        /// Sends a request to the <c>/authz/</c> endpoint for getting an authorization decision. This authorization decision
        /// may only check for authorization, or it may consume a license.
        /// </summary>
        /// <param name="authorizedItem">Name of the item for which authorization is requested.</param>
        /// <param name="responseType">The <see cref="ResponseType"/> requested from the server, or <c>null</c> for server default.</param>
        /// <param name="consume"><c>true</c> to consume a license, <c>false</c> otherwise.</param>
        /// <param name="consumptionMode">Consumption mode: <see cref="ConsumptionMode.Cache"/> for short-term consumption by online clients,
        /// <see cref="ConsumptionMode.Checkout"/> for longer term consumption by clients that may go offline.</param>
        /// <param name="additionalClaims">List of additional license consumption claims.
        /// If <c>null</c> or empty, no additional claims are used.</param>
        /// <returns><see cref="AuthorizationDecision"/> object representing the authorization decision response from the server.</returns>
        public async Task <AuthorizationDecision> CheckOrConsumeAsync(
            string authorizedItem,
            bool consume = false,
            ResponseType responseType       = null,
            ConsumptionMode consumptionMode = ConsumptionMode.Cache,
            IList <KeyValuePair <string, string> > additionalClaims = null)
        {
            var authzDecisionRequestUri = BuildCheckOrConsumeUri(
                new string[] { authorizedItem },
                responseType,
                consume,
                consumptionMode,
                additionalClaims);
            var method       = consume ? HttpMethod.Post : HttpMethod.Get;
            var responseData = await SendAuthorizationRequestAsync(authzDecisionRequestUri, method);

            var responseBody        = responseData.Key;
            var responseContentType = responseData.Value;

            return(AuthorizationDecision.FromServerResponse(authorizedItem, responseBody, responseContentType, AuthzApiConfig.SignerKey));
        }