pkce_challenge 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -16
- data/gemfiles/pkce_challenge-0.2.0.gem +0 -0
- data/gemfiles/pkce_challenge-1.0.0.gem +0 -0
- data/lib/pkce_challenge/challenge.rb +14 -18
- data/lib/pkce_challenge/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ecf2db55010f4dbfc0a506b8a28a6f79e61a3417b6b68d183c52a20379857a3
|
4
|
+
data.tar.gz: 01ea88cbc4da0fa3d07b037ad890ae634d9b3a91650f9709fcbff8cbd48fb130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac7c704a12cfc3df964510a305f7977ccc915b3b7ccbac061d4dbd29355a1b313fe12879aefa823bed8e4e0c57851fb4ffd88682550477c2eaae6958c1f9eab8
|
7
|
+
data.tar.gz: e7b70a852a3431520befeadeec22b682401ed5492bf5da69a887da02744e9a45d8fc49485874c77d976125693a8e4e9401ab71666710d8ca9e9f5061f4252055
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# PKCE Code challenge generator
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
PKCE flow code verifier and code challenge **generator**
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,29 +20,30 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
23
|
+
To generate the code verifier and challenge simply run:
|
24
|
+
|
25
25
|
```ruby
|
26
|
-
|
26
|
+
PkceChallenge.challenge
|
27
27
|
```
|
28
28
|
|
29
|
+
Or with the char length option:
|
30
|
+
|
29
31
|
```ruby
|
30
|
-
|
32
|
+
PkceChallenge.challenge(char_length: 128)
|
31
33
|
```
|
32
34
|
|
33
|
-
|
35
|
+
Additionally you can run:
|
34
36
|
```ruby
|
35
|
-
|
37
|
+
pkce_challenge = PkceChallenge.challenge
|
38
|
+
pkce_challenge = PkceChallenge.challenge(char_length: 128) # or with char_length option
|
36
39
|
```
|
37
40
|
|
38
|
-
|
41
|
+
Returned value is an instance of PkceChallenge::Challenge class which will have the following methods:
|
39
42
|
```ruby
|
40
|
-
#
|
41
|
-
|
42
|
-
2.6.0 :003 > PkceChallenge.challenge(char_length: 50)
|
43
|
-
|
44
|
-
=> #<PkceChallenge::Challenge:0x00007f894f20b9a0 @char_length=50, @code_verifier="0St0oCRzGDFj_iIxB8PCwaMPvGLk8vQxDfJIoC_zU56XwwQM21", @code_challenge="01g9RYPZOjpVFB-BBQhd6OC70jlgPFzJ6ie5YkSC7rI">
|
43
|
+
pkce_challenge.code_verifier # a dynamically created cryptographically random key
|
44
|
+
pkce_challenge.code_challenge # a BASE64-URL-encoded string of the SHA256 hash of the code verifier
|
45
45
|
```
|
46
46
|
|
47
|
-
|
48
47
|
## Development
|
49
48
|
|
50
49
|
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.
|
@@ -53,7 +52,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
53
52
|
|
54
53
|
## Contributing
|
55
54
|
|
56
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/samuelralak/pkce_challenge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
57
56
|
|
58
57
|
## License
|
59
58
|
|
Binary file
|
Binary file
|
@@ -1,34 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "digest"
|
4
|
+
require "securerandom"
|
4
5
|
|
5
6
|
module PkceChallenge
|
6
7
|
class Challenge
|
7
8
|
attr_accessor :code_verifier, :code_challenge
|
8
9
|
|
9
10
|
def initialize(options = {})
|
10
|
-
@
|
11
|
-
|
12
|
-
unless @char_length.between?(CHAR_LENGTH[:min], CHAR_LENGTH[:max])
|
13
|
-
raise PkceChallenge::LengthOutOfRangeError
|
14
|
-
end
|
15
|
-
|
11
|
+
@options = options
|
16
12
|
@code_verifier = generate_code_verifier
|
17
13
|
@code_challenge = generate_pkce_challenge
|
18
14
|
end
|
19
15
|
|
20
16
|
# constants definition
|
21
17
|
|
22
|
-
CHAR_RANGE = [
|
23
|
-
*"A".."Z",
|
24
|
-
*"a".."z",
|
25
|
-
*"0".."9",
|
26
|
-
"-",
|
27
|
-
".",
|
28
|
-
"_",
|
29
|
-
"~",
|
30
|
-
].freeze
|
31
|
-
|
32
18
|
CHAR_LENGTH = {
|
33
19
|
default: 48,
|
34
20
|
max: 128,
|
@@ -38,11 +24,21 @@ module PkceChallenge
|
|
38
24
|
private
|
39
25
|
|
40
26
|
def generate_code_verifier
|
41
|
-
|
27
|
+
length = (@options[:char_length] || CHAR_LENGTH[:default]).to_i
|
28
|
+
|
29
|
+
unless length.between?(CHAR_LENGTH[:min], CHAR_LENGTH[:max])
|
30
|
+
raise PkceChallenge::LengthOutOfRangeError
|
31
|
+
end
|
32
|
+
|
33
|
+
urlsafe_base64(SecureRandom.base64((length * 3) / 4))
|
42
34
|
end
|
43
35
|
|
44
36
|
def generate_pkce_challenge
|
45
|
-
Digest::SHA256.base64digest(@code_verifier)
|
37
|
+
urlsafe_base64(Digest::SHA256.base64digest(@code_verifier))
|
38
|
+
end
|
39
|
+
|
40
|
+
def urlsafe_base64(base64_str)
|
41
|
+
base64_str.tr("+/", "-_").tr("=", "")
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pkce_challenge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Ralak
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
88
|
- gemfiles/pkce_challenge-0.1.0.gem
|
89
|
+
- gemfiles/pkce_challenge-0.2.0.gem
|
90
|
+
- gemfiles/pkce_challenge-1.0.0.gem
|
89
91
|
- lib/pkce_challenge.rb
|
90
92
|
- lib/pkce_challenge/challenge.rb
|
91
93
|
- lib/pkce_challenge/version.rb
|