Skip to content

Commit

Permalink
Fix indentation in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 9, 2022
1 parent 37a0d9e commit b4f9f1d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,26 @@ puts decoded_token
An object implementing custom signing or verification behaviour can be passed in the `algorithm` option when encoding and decoding. The given object needs to implement the method `valid_alg?` and `verify` and/or `alg` and `sign`, depending if object is used for encoding or decoding.

```ruby
module CustomHS512Algorithm
def self.alg
'HS512'
end
module CustomHS512Algorithm
def self.alg
'HS512'
end

def self.valid_alg?(alg_to_validate)
alg_to_validate == alg
end
def self.valid_alg?(alg_to_validate)
alg_to_validate == alg
end

def self.sign(data:, signing_key:)
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), data, signing_key)
end
def self.sign(data:, signing_key:)
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), data, signing_key)
end

def self.verify(data:, signature:, verification_key:)
::OpenSSL.secure_compare(sign(data: data, signing_key: verification_key), signature)
end
def self.verify(data:, signature:, verification_key:)
::OpenSSL.secure_compare(sign(data: data, signing_key: verification_key), signature)
end
end

token = ::JWT.encode({'pay' => 'load'}, 'secret', CustomHS512Algorithm)
payload, header = ::JWT.decode(token, 'secret', true, algorithm: CustomHS512Algorithm)
token = ::JWT.encode({'pay' => 'load'}, 'secret', CustomHS512Algorithm)
payload, header = ::JWT.decode(token, 'secret', true, algorithm: CustomHS512Algorithm)
```

## Support for reserved claim names
Expand Down

0 comments on commit b4f9f1d

Please sign in to comment.