Jelle
Jelle
Explore posts from servers
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
I fixed it with this
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
Im pretty sure you just POST this
{
"applicationIdentifier": "<application_identifier>",
"subscriberId": "<subscriberId>",
"hmacHash": "<hash>"
}
{
"applicationIdentifier": "<application_identifier>",
"subscriberId": "<subscriberId>",
"hmacHash": "<hash>"
}
You're not supposed to send your api key over from the client
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
Youre not sending the hmac hash though
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
And that it's sent correctly to the novu api
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
Are you sure you're using the correct values everywhere?
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
Yep it does
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
Let me check if it still works in our app lmao
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
I don't really see anything wrong in your code though, looks the same
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
This is my implementation, ComputeHash(string) is called with the subscriberId
/// <summary>
/// Used to generate HMAC encrypted userIds for using the Novu Notification Center API.
/// See: <a href="https://docs.novu.co/notification-center/client/react/get-started#enabling-hmac-encryption">Novu Docs</a> for more info
/// </summary>
public sealed class NovuNotificationCenterHashProvider : INotificationCenterHashProvider, IDisposable
{
private readonly HMACSHA256 _hmac;

/// <param name="key">The secret key for HMACSHA256 encryption. The key can be any length. However, the recommended size is 64 bytes. If the key is more than 64 bytes long, it is hashed (using SHA-256) to derive a 64-byte key. If it is less than 64 bytes long, it is padded to 64 bytes.</param>
/// <exception cref="ArgumentNullException">Thrown if <see cref="key"/> is null or empty</exception>
public NovuNotificationCenterHashProvider(string key)
{
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));

_hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
}

public NovuNotificationCenterHashProvider(IOptions<NovuConfiguration> options) : this(options.Value.ApiKey!)
{
}

public string ComputeHash(string source)
{
var hash = _hmac.ComputeHash(Encoding.UTF8.GetBytes(source));

return ToHex(hash);
}

private static string ToHex(IReadOnlyCollection<byte> hash)
{
var hexBuilder = new StringBuilder(hash.Count * 2);
foreach (var b in hash)
{
// The 'x2' format generates two lowercased hex characters per entry
hexBuilder.Append($"{b:x2}");
}

return hexBuilder.ToString();
}

public void Dispose()
{
_hmac.Dispose();
}
}
/// <summary>
/// Used to generate HMAC encrypted userIds for using the Novu Notification Center API.
/// See: <a href="https://docs.novu.co/notification-center/client/react/get-started#enabling-hmac-encryption">Novu Docs</a> for more info
/// </summary>
public sealed class NovuNotificationCenterHashProvider : INotificationCenterHashProvider, IDisposable
{
private readonly HMACSHA256 _hmac;

/// <param name="key">The secret key for HMACSHA256 encryption. The key can be any length. However, the recommended size is 64 bytes. If the key is more than 64 bytes long, it is hashed (using SHA-256) to derive a 64-byte key. If it is less than 64 bytes long, it is padded to 64 bytes.</param>
/// <exception cref="ArgumentNullException">Thrown if <see cref="key"/> is null or empty</exception>
public NovuNotificationCenterHashProvider(string key)
{
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));

_hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
}

public NovuNotificationCenterHashProvider(IOptions<NovuConfiguration> options) : this(options.Value.ApiKey!)
{
}

public string ComputeHash(string source)
{
var hash = _hmac.ComputeHash(Encoding.UTF8.GetBytes(source));

return ToHex(hash);
}

private static string ToHex(IReadOnlyCollection<byte> hash)
{
var hexBuilder = new StringBuilder(hash.Count * 2);
foreach (var b in hash)
{
// The 'x2' format generates two lowercased hex characters per entry
hexBuilder.Append($"{b:x2}");
}

return hexBuilder.ToString();
}

public void Dispose()
{
_hmac.Dispose();
}
}
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
My last message got it working for me
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
May be worth adding to the docs that it should be a lowercased hex hash @Pawan Jain
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
So I fiddled around with it and turns out that it was happening because the Convert.ToHexString generates it in uppercase, converting it to lowercase fixes it
string ToHex(byte[] hash)
{
var hexBuilder = new StringBuilder(hash.Length * 2);
foreach (var b in hash)
{
// The 'x2' format generates two lowercased hex characters per entry
hexBuilder.Append($"{b:x2}");
}

return hexBuilder.ToString();
}
string ToHex(byte[] hash)
{
var hexBuilder = new StringBuilder(hash.Length * 2);
foreach (var b in hash)
{
// The 'x2' format generates two lowercased hex characters per entry
hexBuilder.Append($"{b:x2}");
}

return hexBuilder.ToString();
}
28 replies
NNovu
Created by Jelle on 10/13/2023 in #💬│support
Enabling HMAC for in-app with C#
The novu api key, app id, and the subscriber id seems to be correct
28 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
Well anyway thanks guys! 😄
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
Looks like my work email is just busted 👀
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
Ahh it does work with the default one actually
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
Though I do wonder about using configuration sets in SES, shouldn't the default set apply when sending from Novu?
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
It's not like it's in any suppression lists or something
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
That's .... odd
17 replies
NNovu
Created by Jelle on 10/12/2023 in #💬│support
SES emails not going through
I was sending them to my work e-mail and now i send it to my private email and it works
17 replies