Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielwestendorf/message_verifier.cr
Rails compatible MessageVerifier for Crystal-lang apps
https://github.com/danielwestendorf/message_verifier.cr
Last synced: 9 days ago
JSON representation
Rails compatible MessageVerifier for Crystal-lang apps
- Host: GitHub
- URL: https://github.com/danielwestendorf/message_verifier.cr
- Owner: danielwestendorf
- License: mit
- Created: 2018-08-21T20:19:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-15T20:17:49.000Z (almost 5 years ago)
- Last Synced: 2024-08-01T17:36:10.161Z (3 months ago)
- Language: Crystal
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - message_verifier.cr - Verify and generate Rails `ActiveSupport::MessageVerifier` signed tokens (Misc)
README
# message_verifier.cr
[![Build Status](https://travis-ci.org/danielwestendorf/message_verifier.cr.svg?branch=master)](https://travis-ci.org/danielwestendorf/message_verifier.cr)
Ruby on Rails compatible `ActiveSupport::MessageVerifier` implementation for Crystal. Allows verified message passing back and forth between ruby and crystal-lang implementations.
*Why?* Perhaps you have a microservice written in Crystal and it needs to communicate with a ruby/rails app (or vice-versa), and the data passed between those services needs to be verified to be trustworthy?
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
message_verifier:
github: danielwestendorf/message_verifier.cr
```## Usage
```crystal
require "message_verifier"
```### Verify a message
```crystal
verifier = MessageVerifier::Verifier.new("s3Krit", digest: :sha256)msg = "eyJfcmFpbHMiOnsibWVzc2FnZSI6IkxTMHRDbTFsYzNOaFoyVTZJRTVsZG1WeUlHZHZibTVoSUdkcGRtVWdlVzkxSUhWd0xDQnVaWFpsY2lCbmIyNXVZU0JzWlhRZ2VXOTFJR1J2ZDI0SyIsImV4cCI6IjIwMTktMDEtMDNUMDA6MjI6MjMuMTc4MDQ0MDAwWiIsInB1ciI6ImV4YW1wbGUifX0=--efc837c7279a1030109ec7519418c8934a2cb38d2ce2882a826acf422e432f5e"
puts "Verified message: #{verifier.verify(msg, purpose: :example, parser: :JSON)}"
```### Generate a message
```crystal
verifier = MessageVerifier::Verifier.new("s3Krit", digest: OpenSSL::Algorithm::SHA256)msg = { "foo" => "bar" }
puts verifier.generate(msg.to_json, purpose: :example, expires_at: Time.now + 1.week, parser: :JSON)
```
## See it in action
Examples of passing messages back and forth between ruby and crystal implementations.`gem install activesupport` if not installed already
```bash
$ echo "Very special message" | crystal run examples/sign.cr | ruby examples/verify.rb
``````bash
$ echo "Some other special message" | ruby examples/sign.rb | crystal run examples/verify.cr
```## Progress
- [x] Message expiration dates, freshness
- Messages which have expired will return `nil` or raise a `MessageVerifier::InvalidSignature` exception
- [x] Message purposes
- [x] Message Serializers
- [x] JSON
- [x] YAML
- [x] Signature Digest Algorithms
- [x] All [OpenSSL supported](https://crystal-lang.org/api/0.27.0/OpenSSL/HMAC.html#digest%28algorithm%3ASymbol%2Ckey%2Cdata%29%3ABytes-class-method) algos
- [ ] Rotating keys## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [danielwestendorf](https://github.com/your-github-user) Daniel Westendorf - creator, maintainer