pkce_oauth 0.1.0 → 0.2.1
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/.rubocop.yml +63 -1
- data/CHANGELOG.md +11 -1
- data/Cargo.lock +175 -3
- data/README.md +49 -9
- data/Rakefile +1 -1
- data/ext/pkce_oauth/Cargo.toml +3 -2
- data/ext/pkce_oauth/extconf.rb +3 -3
- data/ext/pkce_oauth/src/lib.rs +16 -5
- data/lib/pkce_oauth/challenge.rb +21 -0
- data/lib/pkce_oauth/code_challenger.rb +9 -0
- data/lib/pkce_oauth/code_verifier.rb +28 -0
- data/lib/pkce_oauth/comparison.rb +15 -0
- data/lib/pkce_oauth/version.rb +1 -1
- data/lib/pkce_oauth.rb +14 -1
- metadata +57 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b199006a114978dddc334598c50e4b9bb70a763a73ad8301cd1267946e06117
|
4
|
+
data.tar.gz: c4dd344fb575d81ef2018be27c3e5a376fdc374dbd9b15b7356c97a0902333bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260b21b7fcaf22ad409fff024933419fff064ec9e6b4e4380a90d936a133448cbe3e899734d90caad9f3225470dbba1ae135a71f20ba4aedfe77ddf90aafd092
|
7
|
+
data.tar.gz: 2b53aca98fd4121ba5e740a108923529b42907a296a37e4cccab410a178ccdfee4dfa72856cb5e88ff9e857cadab0e4f141afb99feaa8a1857cd4bb49e0dff80
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,70 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
1
6
|
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- 'bin/*'
|
9
|
+
- 'tmp/**/*'
|
10
|
+
NewCops: enable
|
2
11
|
TargetRubyVersion: 3.0
|
3
12
|
|
4
13
|
Style/StringLiterals:
|
5
|
-
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: single_quotes
|
6
16
|
|
7
17
|
Style/StringLiteralsInInterpolation:
|
18
|
+
Enabled: true
|
8
19
|
EnforcedStyle: double_quotes
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/BlockDelimiters:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/ModuleFunction:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/ClassAndModuleChildren:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/OptionalBooleanParameter:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Layout/LineLength:
|
37
|
+
Max: 120
|
38
|
+
|
39
|
+
# No space makes the method definition shorter and differentiates
|
40
|
+
# from a regular assignment.
|
41
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
42
|
+
EnforcedStyle: no_space
|
43
|
+
|
44
|
+
RSpec/ExampleLength:
|
45
|
+
Max: 20
|
46
|
+
|
47
|
+
RSpec/NestedGroups:
|
48
|
+
Max: 6
|
49
|
+
|
50
|
+
RSpec/ContextWording:
|
51
|
+
Prefixes:
|
52
|
+
- when
|
53
|
+
- with
|
54
|
+
- without
|
55
|
+
- and
|
56
|
+
- if
|
57
|
+
- in
|
58
|
+
- for
|
59
|
+
|
60
|
+
RSpec/MultipleMemoizedHelpers:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Gemspec/RequireMFA:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Gemspec/DevelopmentDependencies:
|
67
|
+
EnforcedStyle: gemspec
|
68
|
+
|
69
|
+
Metrics/MethodLength:
|
70
|
+
Max: 11
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
## [
|
1
|
+
## [0.2.1] - 2025-03-28
|
2
|
+
### Modified
|
3
|
+
- using rust package pkce
|
4
|
+
|
5
|
+
## [0.2.0] - 2024-12-16
|
6
|
+
### Added
|
7
|
+
- generating random key with charset
|
8
|
+
- url escaping for code challenge
|
9
|
+
|
10
|
+
### Modified
|
11
|
+
- readme
|
2
12
|
|
3
13
|
## [0.1.0] - 2024-12-16
|
4
14
|
|
data/Cargo.lock
CHANGED
@@ -11,6 +11,12 @@ dependencies = [
|
|
11
11
|
"memchr",
|
12
12
|
]
|
13
13
|
|
14
|
+
[[package]]
|
15
|
+
name = "base64"
|
16
|
+
version = "0.21.7"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
19
|
+
|
14
20
|
[[package]]
|
15
21
|
name = "bindgen"
|
16
22
|
version = "0.69.5"
|
@@ -37,6 +43,21 @@ version = "2.6.0"
|
|
37
43
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
38
44
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
39
45
|
|
46
|
+
[[package]]
|
47
|
+
name = "block-buffer"
|
48
|
+
version = "0.10.4"
|
49
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
50
|
+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
51
|
+
dependencies = [
|
52
|
+
"generic-array",
|
53
|
+
]
|
54
|
+
|
55
|
+
[[package]]
|
56
|
+
name = "byteorder"
|
57
|
+
version = "1.5.0"
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
59
|
+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
60
|
+
|
40
61
|
[[package]]
|
41
62
|
name = "cexpr"
|
42
63
|
version = "0.6.0"
|
@@ -63,12 +84,62 @@ dependencies = [
|
|
63
84
|
"libloading",
|
64
85
|
]
|
65
86
|
|
87
|
+
[[package]]
|
88
|
+
name = "cpufeatures"
|
89
|
+
version = "0.2.16"
|
90
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
91
|
+
checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3"
|
92
|
+
dependencies = [
|
93
|
+
"libc",
|
94
|
+
]
|
95
|
+
|
96
|
+
[[package]]
|
97
|
+
name = "crypto-common"
|
98
|
+
version = "0.1.6"
|
99
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
100
|
+
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
101
|
+
dependencies = [
|
102
|
+
"generic-array",
|
103
|
+
"typenum",
|
104
|
+
]
|
105
|
+
|
106
|
+
[[package]]
|
107
|
+
name = "digest"
|
108
|
+
version = "0.10.7"
|
109
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
110
|
+
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
111
|
+
dependencies = [
|
112
|
+
"block-buffer",
|
113
|
+
"crypto-common",
|
114
|
+
]
|
115
|
+
|
66
116
|
[[package]]
|
67
117
|
name = "either"
|
68
118
|
version = "1.13.0"
|
69
119
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
70
120
|
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
71
121
|
|
122
|
+
[[package]]
|
123
|
+
name = "generic-array"
|
124
|
+
version = "0.14.7"
|
125
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
126
|
+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
127
|
+
dependencies = [
|
128
|
+
"typenum",
|
129
|
+
"version_check",
|
130
|
+
]
|
131
|
+
|
132
|
+
[[package]]
|
133
|
+
name = "getrandom"
|
134
|
+
version = "0.2.15"
|
135
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
136
|
+
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
137
|
+
dependencies = [
|
138
|
+
"cfg-if",
|
139
|
+
"libc",
|
140
|
+
"wasi",
|
141
|
+
]
|
142
|
+
|
72
143
|
[[package]]
|
73
144
|
name = "glob"
|
74
145
|
version = "0.3.1"
|
@@ -114,9 +185,9 @@ dependencies = [
|
|
114
185
|
|
115
186
|
[[package]]
|
116
187
|
name = "magnus"
|
117
|
-
version = "0.
|
188
|
+
version = "0.7.1"
|
118
189
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
119
|
-
checksum = "
|
190
|
+
checksum = "3d87ae53030f3a22e83879e666cb94e58a7bdf31706878a0ba48752994146dab"
|
120
191
|
dependencies = [
|
121
192
|
"magnus-macros",
|
122
193
|
"rb-sys",
|
@@ -157,11 +228,32 @@ dependencies = [
|
|
157
228
|
"minimal-lexical",
|
158
229
|
]
|
159
230
|
|
231
|
+
[[package]]
|
232
|
+
name = "pkce"
|
233
|
+
version = "0.2.0"
|
234
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
235
|
+
checksum = "e228dbe2aebd82de09c914fe28d36d3170ed5192e8d52b9c070ee0794519c2d3"
|
236
|
+
dependencies = [
|
237
|
+
"base64",
|
238
|
+
"rand",
|
239
|
+
"sha2",
|
240
|
+
]
|
241
|
+
|
160
242
|
[[package]]
|
161
243
|
name = "pkce_oauth"
|
162
|
-
version = "0.1.
|
244
|
+
version = "0.1.1"
|
163
245
|
dependencies = [
|
164
246
|
"magnus",
|
247
|
+
"pkce",
|
248
|
+
]
|
249
|
+
|
250
|
+
[[package]]
|
251
|
+
name = "ppv-lite86"
|
252
|
+
version = "0.2.20"
|
253
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
254
|
+
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
255
|
+
dependencies = [
|
256
|
+
"zerocopy",
|
165
257
|
]
|
166
258
|
|
167
259
|
[[package]]
|
@@ -182,6 +274,36 @@ dependencies = [
|
|
182
274
|
"proc-macro2",
|
183
275
|
]
|
184
276
|
|
277
|
+
[[package]]
|
278
|
+
name = "rand"
|
279
|
+
version = "0.8.5"
|
280
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
281
|
+
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
282
|
+
dependencies = [
|
283
|
+
"libc",
|
284
|
+
"rand_chacha",
|
285
|
+
"rand_core",
|
286
|
+
]
|
287
|
+
|
288
|
+
[[package]]
|
289
|
+
name = "rand_chacha"
|
290
|
+
version = "0.3.1"
|
291
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
292
|
+
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
293
|
+
dependencies = [
|
294
|
+
"ppv-lite86",
|
295
|
+
"rand_core",
|
296
|
+
]
|
297
|
+
|
298
|
+
[[package]]
|
299
|
+
name = "rand_core"
|
300
|
+
version = "0.6.4"
|
301
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
302
|
+
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
303
|
+
dependencies = [
|
304
|
+
"getrandom",
|
305
|
+
]
|
306
|
+
|
185
307
|
[[package]]
|
186
308
|
name = "rb-sys"
|
187
309
|
version = "0.9.103"
|
@@ -253,6 +375,17 @@ version = "0.3.5"
|
|
253
375
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
254
376
|
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
255
377
|
|
378
|
+
[[package]]
|
379
|
+
name = "sha2"
|
380
|
+
version = "0.10.8"
|
381
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
382
|
+
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
383
|
+
dependencies = [
|
384
|
+
"cfg-if",
|
385
|
+
"cpufeatures",
|
386
|
+
"digest",
|
387
|
+
]
|
388
|
+
|
256
389
|
[[package]]
|
257
390
|
name = "shell-words"
|
258
391
|
version = "1.1.0"
|
@@ -276,12 +409,30 @@ dependencies = [
|
|
276
409
|
"unicode-ident",
|
277
410
|
]
|
278
411
|
|
412
|
+
[[package]]
|
413
|
+
name = "typenum"
|
414
|
+
version = "1.17.0"
|
415
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
416
|
+
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
417
|
+
|
279
418
|
[[package]]
|
280
419
|
name = "unicode-ident"
|
281
420
|
version = "1.0.14"
|
282
421
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
283
422
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
284
423
|
|
424
|
+
[[package]]
|
425
|
+
name = "version_check"
|
426
|
+
version = "0.9.5"
|
427
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
428
|
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
429
|
+
|
430
|
+
[[package]]
|
431
|
+
name = "wasi"
|
432
|
+
version = "0.11.0+wasi-snapshot-preview1"
|
433
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
434
|
+
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
435
|
+
|
285
436
|
[[package]]
|
286
437
|
name = "windows-targets"
|
287
438
|
version = "0.52.6"
|
@@ -345,3 +496,24 @@ name = "windows_x86_64_msvc"
|
|
345
496
|
version = "0.52.6"
|
346
497
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
347
498
|
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
499
|
+
|
500
|
+
[[package]]
|
501
|
+
name = "zerocopy"
|
502
|
+
version = "0.7.35"
|
503
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
504
|
+
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
|
505
|
+
dependencies = [
|
506
|
+
"byteorder",
|
507
|
+
"zerocopy-derive",
|
508
|
+
]
|
509
|
+
|
510
|
+
[[package]]
|
511
|
+
name = "zerocopy-derive"
|
512
|
+
version = "0.7.35"
|
513
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
514
|
+
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
515
|
+
dependencies = [
|
516
|
+
"proc-macro2",
|
517
|
+
"quote",
|
518
|
+
"syn",
|
519
|
+
]
|
data/README.md
CHANGED
@@ -1,30 +1,70 @@
|
|
1
1
|
# PkceOauth
|
2
2
|
|
3
|
-
|
3
|
+
Proof Key for Code Exchange (PKCE) for ruby built with rust.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
```
|
10
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'pkce_oauth'
|
11
11
|
```
|
12
12
|
|
13
|
-
|
13
|
+
## Usage
|
14
14
|
|
15
|
-
```
|
16
|
-
|
15
|
+
```ruby
|
16
|
+
# @return [Hash] keys: code_verifier, code_challenge
|
17
|
+
# code_verifier - random key
|
18
|
+
# code_challenge - Base64 url-encoded string of the SHA256 hash of the code verifier
|
19
|
+
PkceOauth.challenge
|
17
20
|
```
|
18
21
|
|
19
|
-
|
22
|
+
```ruby
|
23
|
+
# @return [Hash] keys: code_verifier, code_challenge
|
24
|
+
PkceOauth.challenge(key_length: 64)
|
25
|
+
```
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# @return [Boolean]
|
29
|
+
PkceOauth.challenge_valid?(code_verifier: code_verifier, code_challenge: code_challenge)
|
30
|
+
```
|
31
|
+
|
32
|
+
### Usage with dry-container
|
33
|
+
|
34
|
+
If you use dry-container for class memoization and use `PkceOauth.challenge` with the same options, then you can add initialized objects to container
|
20
35
|
|
36
|
+
```ruby
|
37
|
+
register('pkce_challenge') { PkceOauth::Challenge.new }
|
38
|
+
register('pkce_comparator') { PkceOauth::Comparison.new }
|
39
|
+
```
|
40
|
+
|
41
|
+
and later call them
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
pkce_challenge.call
|
45
|
+
pkce_comparator.equal?(code_verifier: code_verifier, code_challenge: code_challenge)
|
46
|
+
```
|
47
|
+
|
48
|
+
### Direct usage
|
21
49
|
|
50
|
+
You can directly call generating code verifier and code challenge
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
PkceOauth.generate_code_verifier
|
54
|
+
PkceOauth.generate_limited_code_verifier(64)
|
55
|
+
PkceOauth.generate_code_challenge(code_verifier)
|
56
|
+
```
|
22
57
|
|
23
58
|
## Development
|
24
59
|
|
25
60
|
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.
|
26
61
|
|
27
|
-
|
62
|
+
After changing rust code in ext folder you need to compile code and run tests
|
63
|
+
|
64
|
+
```bash
|
65
|
+
bundle exec rake compile
|
66
|
+
rspec
|
67
|
+
```
|
28
68
|
|
29
69
|
## Contributing
|
30
70
|
|
data/Rakefile
CHANGED
data/ext/pkce_oauth/Cargo.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "pkce_oauth"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.1"
|
4
4
|
edition = "2021"
|
5
5
|
authors = ["Bogdanov Anton <kortirso@gmail.com>"]
|
6
6
|
license = "MIT"
|
@@ -10,4 +10,5 @@ publish = false
|
|
10
10
|
crate-type = ["cdylib"]
|
11
11
|
|
12
12
|
[dependencies]
|
13
|
-
magnus = { version = "0.
|
13
|
+
magnus = { version = "0.7" }
|
14
|
+
pkce = { version = "0.2.0" }
|
data/ext/pkce_oauth/extconf.rb
CHANGED
data/ext/pkce_oauth/src/lib.rs
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
use magnus::{function, prelude::*, Error, Ruby};
|
2
|
+
use pkce;
|
2
3
|
|
3
|
-
fn
|
4
|
-
|
4
|
+
fn generate_limited_code_verifier(length: usize) -> String {
|
5
|
+
String::from_utf8(pkce::code_verifier(length)).expect("REASON")
|
6
|
+
}
|
7
|
+
|
8
|
+
fn generate_code_verifier() -> String {
|
9
|
+
generate_limited_code_verifier(128)
|
10
|
+
}
|
11
|
+
|
12
|
+
fn generate_code_challenge(code_verifier: String) -> String {
|
13
|
+
pkce::code_challenge(&code_verifier.as_bytes())
|
5
14
|
}
|
6
15
|
|
7
16
|
#[magnus::init]
|
8
17
|
fn init(ruby: &Ruby) -> Result<(), Error> {
|
9
|
-
|
10
|
-
|
11
|
-
|
18
|
+
let module = ruby.define_module("PkceOauth")?;
|
19
|
+
module.define_singleton_method("generate_limited_code_verifier", function!(generate_limited_code_verifier, 1))?;
|
20
|
+
module.define_singleton_method("generate_code_verifier", function!(generate_code_verifier, 0))?;
|
21
|
+
module.define_singleton_method("generate_code_challenge", function!(generate_code_challenge, 1))?;
|
22
|
+
Ok(())
|
12
23
|
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PkceOauth
|
4
|
+
class Challenge
|
5
|
+
attr_reader :verifier, :challenger
|
6
|
+
|
7
|
+
def initialize(verifier: CodeVerifier, challenger: CodeChallenger, **options)
|
8
|
+
@verifier = verifier.new(**options.slice(:key_length))
|
9
|
+
@challenger = challenger.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
code_verifier = verifier.call
|
14
|
+
|
15
|
+
{
|
16
|
+
code_verifier: code_verifier,
|
17
|
+
code_challenge: challenger.call(code_verifier: code_verifier)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PkceOauth
|
4
|
+
class CodeVerifier
|
5
|
+
class KeyLengthError < StandardError; end
|
6
|
+
|
7
|
+
MINIMUM_KEY_LENGTH = 43
|
8
|
+
DEFAULT_KEY_LENGTH = 128
|
9
|
+
|
10
|
+
attr_reader :key_length
|
11
|
+
|
12
|
+
def initialize(key_length: DEFAULT_KEY_LENGTH)
|
13
|
+
@key_length = validate_key_length(key_length)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
PkceOauth.generate_limited_code_verifier(key_length)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def validate_key_length(value)
|
23
|
+
return value if value.is_a?(Integer) && value.between?(MINIMUM_KEY_LENGTH, DEFAULT_KEY_LENGTH)
|
24
|
+
|
25
|
+
raise KeyLengthError, 'Key length should be number between 43 and 128'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PkceOauth
|
4
|
+
class Comparison
|
5
|
+
attr_reader :challenger
|
6
|
+
|
7
|
+
def initialize(challenger: CodeChallenger)
|
8
|
+
@challenger = challenger.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def equal?(code_verifier:, code_challenge:)
|
12
|
+
challenger.call(code_verifier: code_verifier) == code_challenge
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/pkce_oauth/version.rb
CHANGED
data/lib/pkce_oauth.rb
CHANGED
@@ -2,8 +2,21 @@
|
|
2
2
|
|
3
3
|
require_relative 'pkce_oauth/version'
|
4
4
|
require_relative 'pkce_oauth/pkce_oauth'
|
5
|
+
require_relative 'pkce_oauth/code_verifier'
|
6
|
+
require_relative 'pkce_oauth/code_challenger'
|
7
|
+
require_relative 'pkce_oauth/challenge'
|
8
|
+
require_relative 'pkce_oauth/comparison'
|
5
9
|
|
6
10
|
module PkceOauth
|
11
|
+
module_function
|
12
|
+
|
7
13
|
class Error < StandardError; end
|
8
|
-
|
14
|
+
|
15
|
+
def challenge(...)
|
16
|
+
PkceOauth::Challenge.new(...).call
|
17
|
+
end
|
18
|
+
|
19
|
+
def challenge_valid?(...)
|
20
|
+
PkceOauth::Comparison.new.equal?(...)
|
21
|
+
end
|
9
22
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pkce_oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdanov Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '13.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '13.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
28
|
+
name: rake-compiler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rb_sys
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.9.91
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.9.91
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.39'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
69
111
|
description: Code verifier and challenge generator for use in PKCE Oauth2.
|
70
112
|
email:
|
71
113
|
- kortirso@gmail.com
|
@@ -86,6 +128,10 @@ files:
|
|
86
128
|
- ext/pkce_oauth/extconf.rb
|
87
129
|
- ext/pkce_oauth/src/lib.rs
|
88
130
|
- lib/pkce_oauth.rb
|
131
|
+
- lib/pkce_oauth/challenge.rb
|
132
|
+
- lib/pkce_oauth/code_challenger.rb
|
133
|
+
- lib/pkce_oauth/code_verifier.rb
|
134
|
+
- lib/pkce_oauth/comparison.rb
|
89
135
|
- lib/pkce_oauth/version.rb
|
90
136
|
- sig/pkce_oauth.rbs
|
91
137
|
homepage: https://github.com/kortirso/pkce_oauth
|