public static MagicLink DecryptMagicLink(string token, string eDiscoveryLinkEncryptionKey) { // First we take the token and URL decode it. var decodedToken = HttpUtility.UrlDecode(token); // Next we need to decrypt the cipher text var decryptedJson = TokenEncryption.Decrypt(decodedToken, eDiscoveryLinkEncryptionKey); // Now we want to deserialize this back out to a magic link object. var magicLink = JsonConvert.DeserializeObject <MagicLink>(decryptedJson); // goofy logic for backwards compatibility // if User.Identifier not specified, that means UserKey is populated, build a UserIdentifier #pragma warning disable CS0612 // Type or member is obsolete if (magicLink.User != null) { magicLink.UserIdentifier = new UserIdentifier(magicLink.OrganizationKey, magicLink.User.UserKey); } if (magicLink.OrganizationKey != null) { magicLink.FolderIdentifier = new FolderIdentifier(magicLink.OrganizationKey, magicLink.FolderKey); } #pragma warning restore CS0612 // Type or member is obsolete return(magicLink); }
public async Task <IActionResult> Post(string token) { var decrypted = TokenEncryption.Decrypt(token, DocumentsAPIConfiguration.APITokenKey); var callback = JsonConvert.DeserializeObject <CallbackModel>(decrypted); if (callback.FileIdentifier != null && Request.ContentLength.HasValue && Request.ContentLength.Value > 0 ) { SecurityContext.AssumeToken(callback.Token); var file = await FileStore.GetOneAsync(callback.FileIdentifier) ?? new FileModel(callback.FileIdentifier); file.Length = Request.ContentLength.Value; file.MimeType = Request.ContentType ?? "application/octet-stream"; file.Name = "callback"; file = await FileContentsService.UploadEntireFileAsync(file, Request.Body); } await QueueSender.SendAsync(callback.Queue, JsonConvert.SerializeObject(callback)); SuppressWrapper = true; return(Ok()); }
public string CreateCallback([FromBody] CallbackModel callback) { var token = TokenEncryption.Encrypt( JsonConvert.SerializeObject(callback), DocumentsAPIConfiguration.APITokenKey ); return(string.Format(DocumentsAPIConfiguration.CallbackURL, WebUtility.UrlEncode(token))); }
public static string CreateMagicLink(RecipientRequestBase addRecipientRequest, string landingLocation, string passphrase, FolderIdentifier folderIdentifier, DateTime?expirationDate, UserIdentifier userIdentifier) { // Create the magic link object. var magicLink = new MagicLink() { RecipientEmail = addRecipientRequest.RecipientEmail, ExipirationDate = expirationDate.GetValueOrDefault(), FolderIdentifier = folderIdentifier, UserIdentifier = userIdentifier }; // Serialize and encrypt that magic link, which we'll turn into a token. This is a touple, that will return the cipher, and IV. var cipherIV = TokenEncryption.Encrypt(JsonConvert.SerializeObject(magicLink, Formatting.None), passphrase); // Build the full landing url. Encrypted token, and plain IV return(String.Format($"{landingLocation}/{HttpUtility.UrlEncode(cipherIV)}")); }