Skip to content

Commit

Permalink
Remove padding from HMAC generation to avoid confusion in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
supercairos committed Jan 9, 2023
1 parent 9279963 commit e60949d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion token/hmac/hmacsha.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *HMACStrategy) GenerateHMACForString(ctx context.Context, text string) (
bytes := []byte(text)
hashBytes := c.generateHMAC(ctx, bytes, &signingKey)

b64 := base64.URLEncoding.EncodeToString(hashBytes)
b64 := base64.RawURLEncoding.EncodeToString(hashBytes)
return b64, nil
}

Expand Down
8 changes: 4 additions & 4 deletions token/hmac/hmacsha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ func TestGenerateFromString(t *testing.T) {
}{
{
text: "",
hash: "-n7EqD-bXkY3yYMH-ctEAGV8XLkU7Y6Bo6pbyT1agGA=",
hash: "-n7EqD-bXkY3yYMH-ctEAGV8XLkU7Y6Bo6pbyT1agGA",
},
{
text: " ",
hash: "zXJvonHTNSOOGj_QKl4RpIX_zXgD2YfXUfwuDKaTTIg=",
hash: "zXJvonHTNSOOGj_QKl4RpIX_zXgD2YfXUfwuDKaTTIg",
},
{
text: "Test",
hash: "TMeEaHS-cDC2nijiesCNtsOyBqHHtzWqAcWvceQT50g=",
hash: "TMeEaHS-cDC2nijiesCNtsOyBqHHtzWqAcWvceQT50g",
},
{
text: "AnotherTest1234",
hash: "zHYDOZGjzhVjx5r8RlBhpnJemX5JxEEBUjVT01n3IFM=",
hash: "zHYDOZGjzhVjx5r8RlBhpnJemX5JxEEBUjVT01n3IFM",
},
} {
hash, _ := cg.GenerateHMACForString(context.Background(), c.text)
Expand Down

0 comments on commit e60949d

Please sign in to comment.