Project

pkce_oauth

0.0
The project is in a healthy, maintained state
Code verifier and challenge generator for use in PKCE Oauth2.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 13.0
~> 0.9.91
 Project Readme

PkceOauth

Proof Key for Code Exchange (PKCE) for ruby built with rust.

Installation

Add this line to your application's Gemfile:

gem 'pkce_oauth'

Usage

# @return [Hash] keys: code_verifier, code_challenge
# code_verifier - random key
# code_challenge - Base64 url-encoded string of the SHA256 hash of the code verifier
PkceOauth.challenge
# @return [Hash] keys: code_verifier, code_challenge
PkceOauth.challenge(key_length: 64)
# @return [Boolean]
PkceOauth.challenge_valid?(code_verifier: code_verifier, code_challenge: code_challenge)

Usage with dry-container

If you use dry-container for class memoization and use PkceOauth.challenge with the same options, then you can add initialized objects to container

register('pkce_challenge') { PkceOauth::Challenge.new }
register('pkce_comparator') { PkceOauth::Comparator.new }

and later call them

pkce_challenge.call
pkce_comparator.equal?(code_verifier: code_verifier, code_challenge: code_challenge)

Direct usage

You can directly call generating code verifier and code challenge

PkceOauth.generate_code_verifier
PkceOauth.generate_limited_code_verifier(64)
PkceOauth.generate_code_challenge(code_verifier)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

After changing rust code in ext folder you need to compile code and run tests

bundle exec rake compile
rspec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kortirso/pkce_oauth.

License

The gem is available as open source under the terms of the MIT License.