public ByteArrayContent WopiTokenInputToWopiTokenContent()
        {
            var wopiToken = new WopiTokenInput(
                "ApplicationId",
                Guid.NewGuid(),
                Guid.NewGuid(),
                "*****@*****.**",
                Guid.NewGuid(),
                "Brandname",
                "BrandUrl",
                "FriendlyName",
                new List <string> {
                "A", "B", "C"
            },
                TimeSpan.FromMinutes(1));

            var body   = JsonSerializer.Serialize(wopiToken);
            var buffer = System.Text.Encoding.UTF8.GetBytes(body);

            var result = new ByteArrayContent(buffer);

            result.Headers.ContentType = new MediaTypeHeaderValue(GenericConstants.JsonMediaType);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Generates a <see cref="WopiToken"/> from <see cref="WopiTokenInput"/>
        /// </summary>
        /// <param name="input"></param>
        /// <returns><see cref="WopiToken"/></returns>
        public Task <WopiToken> GenerateWopiTokenAsync(WopiTokenInput input)
        {
            Argument.IsNotNull(nameof(input), input);

            var claims = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(CustomClaimTypes.ApplicationIdType, input.ApplicationId),
                new KeyValuePair <string, string>(CustomClaimTypes.DocumentIdType, input.DocumentId.ToString()),
                new KeyValuePair <string, string>(ISynergy.Framework.Core.Constants.ClaimTypes.AccountIdType, input.TenantId.ToString()),
                new KeyValuePair <string, string>(ISynergy.Framework.Core.Constants.ClaimTypes.UserIdType, input.UserId.ToString())
            };

            var token = jwtTokenService.GenerateJwtToken(new TokenRequest(
                                                             input.Username,
                                                             claims,
                                                             input.Roles,
                                                             input.Expiration
                                                             ));

            if (token is Token)
            {
                return(Task.FromResult(
                           new WopiToken(
                               input.ApplicationId,
                               input.TenantId,
                               input.UserId,
                               input.Username,
                               input.DocumentId,
                               input.BrandName,
                               input.BrandUrl,
                               input.FriendlyName,
                               input.Roles,
                               input.Expiration,
                               token.AccessToken)));
            }

            return(null);
        }
 public Task <WopiToken> GenerateWopiTokenAsync([FromBody] WopiTokenInput input) =>
 tokenManager.GenerateWopiTokenAsync(input);