-
-
Notifications
You must be signed in to change notification settings - Fork 624
Expand file tree
/
Copy pathfile.README.html
More file actions
1386 lines (1076 loc) · 80.4 KB
/
file.README.html
File metadata and controls
1386 lines (1076 loc) · 80.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
File: README
— Documentation by YARD 0.9.37
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "README";
relpath = '';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="file_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="_index.html">Index</a> »
<span class="title">File: README</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><div id='filecontents'><p><a href="https://discord.gg/3qme4XHNKN"><img src="https://logos.galtzo.com/assets/images/galtzo-floss/avatar-192px.svg" alt="Galtzo FLOSS Logo by Aboling0, CC BY-SA 4.0"></a> <a href="https://www.ruby-lang.org/"><img src="https://logos.galtzo.com/assets/images/ruby-lang/avatar-192px.svg" alt="ruby-lang Logo, Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5"></a> <a href="https://github.com/ruby-oauth/oauth2"><img src="https://logos.galtzo.com/assets/images/oauth/oauth2/avatar-192px.svg" alt="oauth2 Logo by Chris Messina, CC BY-SA 3.0"></a></p>
<h1 id="-oauth-20-authorization-framework">🔐 OAuth 2.0 Authorization Framework</h1>
<p>⭐️ including OAuth 2.1 draft spec & OpenID Connect (OIDC)</p>
<p><a href="https://rubygems.org/gems/oauth2"><img src="https://img.shields.io/gem/v/oauth2.svg" alt="Version"></a> <a href="http://github.com/ruby-oauth/oauth2/releases"><img src="https://img.shields.io/github/tag/ruby-oauth/oauth2.svg" alt="GitHub tag (latest SemVer)"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-259D6C.svg" alt="License: MIT"></a> <a href="https://rubygems.org/gems/oauth2"><img src="https://img.shields.io/gem/rd/oauth2.svg" alt="Downloads Rank"></a> <a href="https://www.codetriage.com/ruby-oauth/oauth2"><img src="https://www.codetriage.com/ruby-oauth/oauth2/badges/users.svg" alt="Open Source Helpers"></a> <a href="https://coveralls.io/github/ruby-oauth/oauth2?branch=main"><img src="https://coveralls.io/repos/github/ruby-oauth/oauth2/badge.svg?branch=main" alt="Coveralls Test Coverage"></a> <a href="https://qlty.sh/gh/ruby-oauth/projects/oauth2/metrics/code?sort=coverageRating"><img src="https://qlty.sh/gh/ruby-oauth/projects/oauth2/coverage.svg" alt="QLTY Test Coverage"></a> <a href="https://qlty.sh/gh/ruby-oauth/projects/oauth2"><img src="https://qlty.sh/gh/ruby-oauth/projects/oauth2/maintainability.svg" alt="QLTY Maintainability"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/heads.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/heads.yml/badge.svg" alt="CI Heads"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/current-runtime-heads.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/current-runtime-heads.yml/badge.svg" alt="CI Runtime Dependencies @ HEAD"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/current.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/current.yml/badge.svg" alt="CI Current"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/truffle.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/truffle.yml/badge.svg" alt="CI Truffle Ruby"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/jruby.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/jruby.yml/badge.svg" alt="CI JRuby"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/locked_deps.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/locked_deps.yml/badge.svg" alt="Deps Locked"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/unlocked_deps.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/unlocked_deps.yml/badge.svg" alt="Deps Unlocked"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/supported.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/supported.yml/badge.svg" alt="CI Supported"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/legacy.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/legacy.yml/badge.svg" alt="CI Legacy"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/unsupported.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/unsupported.yml/badge.svg" alt="CI Unsupported"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/ancient.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/ancient.yml/badge.svg" alt="CI Ancient"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/caboose.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/caboose.yml/badge.svg" alt="CI Caboose is an absolute WAGON"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/coverage.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/coverage.yml/badge.svg" alt="CI Test Coverage"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/style.yml"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/style.yml/badge.svg" alt="CI Style"></a> <a href="https://github.com/ruby-oauth/oauth2/security/code-scanning"><img src="https://github.com/ruby-oauth/oauth2/actions/workflows/codeql-analysis.yml/badge.svg" alt="CodeQL"></a></p>
<p>If ☝️ <code>ci_badges.map(&:color).detect { it != "green"}</code> <a href="https://discord.gg/3qme4XHNKN">let me know</a>, as I may have missed the <a href="https://discord.gg/3qme4XHNKN">discord notification</a>.</p>
<hr>
<p>OTOH, if <code>ci_badges.map(&:color).all? { it == "green"}</code> 👇️ send money so I can do more of this. FLOSS maintenance is now my full-time job.</p>
<p><a href="https://opencollective.com/ruby-oauth#backer"><img src="https://opencollective.com/ruby-oauth/backers/badge.svg?style=flat" alt="OpenCollective Backers"></a> <a href="https://opencollective.com/ruby-oauth#sponsor"><img src="https://opencollective.com/ruby-oauth/sponsors/badge.svg?style=flat" alt="OpenCollective Sponsors"></a> <a href="https://github.com/sponsors/pboling"><img src="https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github" alt="Sponsor Me on Github"></a> <a href="https://liberapay.com/pboling/donate"><img src="https://img.shields.io/liberapay/goal/pboling.svg?logo=liberapay&color=a51611&style=flat" alt="Liberapay Goal Progress"></a> <a href="https://www.paypal.com/paypalme/peterboling"><img src="https://img.shields.io/badge/donate-paypal-a51611.svg?style=flat&logo=paypal" alt="Donate on PayPal"></a> <a href="https://www.buymeacoffee.com/pboling"><img src="https://img.shields.io/badge/buy_me_a_coffee-%E2%9C%93-a51611.svg?style=flat" alt="Buy me a coffee"></a> <a href="https://polar.sh/pboling"><img src="https://img.shields.io/badge/polar-donate-a51611.svg?style=flat" alt="Donate on Polar"></a> <a href="https://ko-fi.com/O5O86SNP4"><img src="https://img.shields.io/badge/ko--fi-%E2%9C%93-a51611.svg?style=flat" alt="Donate to my FLOSS or refugee efforts at ko-fi.com"></a> <a href="https://patreon.com/galtzo"><img src="https://img.shields.io/badge/patreon-donate-a51611.svg?style=flat" alt="Donate to my FLOSS or refugee efforts using Patreon"></a></p>
<h2 id="-synopsis">🌻 Synopsis</h2>
<p>OAuth 2.0 is the industry-standard protocol for authorization.<br>
OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications,<br>
desktop applications, mobile phones, and living room devices.<br>
This is a RubyGem for implementing OAuth 2.0 clients (not servers) in Ruby applications.</p>
<h3 id="quick-example">Quick Example</h3>
<details>
<summary>Convert the following `curl` command into a token request using this gem...</summary>
```shell
curl --request POST \
--url 'https://login.microsoftonline.com/REDMOND_REDACTED/oauth2/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=REDMOND_CLIENT_ID \
--data client_secret=REDMOND_CLIENT_SECRET \
--data resource=REDMOND_RESOURCE_UUID
```
NOTE: In the ruby version below, certain params are passed to the `get_token` call, instead of the client creation.
```ruby
OAuth2::Client.new(
"REDMOND_CLIENT_ID", # client_id
"REDMOND_CLIENT_SECRET", # client_secret
auth_scheme: :request_body, # Other modes are supported: :basic_auth, :tls_client_auth, :private_key_jwt
token_url: "oauth2/token", # relative path, except with leading `/`, then absolute path
site: "https://login.microsoftonline.com/REDMOND_REDACTED",
). # The base path for token_url when it is relative
client_credentials. # There are many other types to choose from!
get_token(resource: "REDMOND_RESOURCE_UUID")
```
NOTE: `header` - The content type specified in the `curl` is already the default!
</details>
<p>If it seems like you are in the wrong place, you might try one of these:</p>
<ul>
<li><a href="https://oauth.net/2/">OAuth 2.0 Spec</a></li>
<li>
<a href="https://github.com/doorkeeper-gem/doorkeeper">doorkeeper gem</a> for OAuth 2.0 server/provider implementation.</li>
<li>
<a href="https://gitlab.com/ruby-oauth/oauth">oauth sibling gem</a> for OAuth 1.0a implementations in Ruby.</li>
</ul>
<h2 id="-info-you-can-shake-a-stick-at">💡 Info you can shake a stick at</h2>
<table>
<thead>
<tr>
<th>Tokens to Remember</th>
<th>
<a href="https://rubygems.org/gems/oauth2"><img src="https://img.shields.io/badge/name-oauth2-3C2D2D.svg?style=square&logo=rubygems&logoColor=red" alt="Gem name"></a> <a href="https://github.com/ruby-oauth/oauth2"><img src="https://img.shields.io/badge/namespace-OAuth2-3C2D2D.svg?style=square&logo=ruby&logoColor=white" alt="Gem namespace"></a>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Works with JRuby</td>
<td>
<img src="https://img.shields.io/badge/JRuby-9.1_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.1 Compat"> <img src="https://img.shields.io/badge/JRuby-9.2_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.2 Compat"> <img src="https://img.shields.io/badge/JRuby-9.3_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.3 Compat"> <br> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/jruby.yml"><img src="https://img.shields.io/badge/JRuby-9.4-FBE742?style=for-the-badge&logo=ruby&logoColor=red" alt="JRuby 9.4 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/current.yml"><img src="https://img.shields.io/badge/JRuby-current-FBE742?style=for-the-badge&logo=ruby&logoColor=green" alt="JRuby 10.0 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/heads.yml"><img src="https://img.shields.io/badge/JRuby-HEAD-FBE742?style=for-the-badge&logo=ruby&logoColor=blue" alt="JRuby HEAD Compat"></a>
</td>
</tr>
<tr>
<td>Works with Truffle Ruby</td>
<td>
<img src="https://img.shields.io/badge/Truffle_Ruby-22.3_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 22.3 Compat"> <img src="https://img.shields.io/badge/Truffle_Ruby-23.0_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 23.0 Compat"> <br> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/truffle.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-23.1-34BCB1?style=for-the-badge&logo=ruby&logoColor=pink" alt="Truffle Ruby 23.1 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/current.yml"><img src="https://img.shields.io/badge/Truffle_Ruby-current-34BCB1?style=for-the-badge&logo=ruby&logoColor=green" alt="Truffle Ruby 24.1 Compat"></a>
</td>
</tr>
<tr>
<td>Works with MRI Ruby 3</td>
<td>
<a href="https://github.com/ruby-oauth/oauth2/actions/workflows/legacy.yml"><img src="https://img.shields.io/badge/Ruby-3.0-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.0 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.1-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.1 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.2-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.2 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/supported.yml"><img src="https://img.shields.io/badge/Ruby-3.3-CC342D?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 3.3 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/current.yml"><img src="https://img.shields.io/badge/Ruby-current-CC342D?style=for-the-badge&logo=ruby&logoColor=green" alt="Ruby 3.4 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/heads.yml"><img src="https://img.shields.io/badge/Ruby-HEAD-CC342D?style=for-the-badge&logo=ruby&logoColor=blue" alt="Ruby HEAD Compat"></a>
</td>
</tr>
<tr>
<td>Works with MRI Ruby 2</td>
<td>
<img src="https://img.shields.io/badge/Ruby-2.2_(%F0%9F%9A%ABCI)-AABBCC?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.2 Compat"> <br> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.3-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.3 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.4-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.4 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/ancient.yml"><img src="https://img.shields.io/badge/Ruby-2.5-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.5 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/unsupported.yml"><img src="https://img.shields.io/badge/Ruby-2.6-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.6 Compat"></a> <a href="https://github.com/ruby-oauth/oauth2/actions/workflows/unsupported.yml"><img src="https://img.shields.io/badge/Ruby-2.7-DF00CA?style=for-the-badge&logo=ruby&logoColor=white" alt="Ruby 2.7 Compat"></a>
</td>
</tr>
<tr>
<td>Source</td>
<td>
<a href="https://gitlab.com/ruby-oauth/oauth2/"><img src="https://img.shields.io/badge/GitLab-FBA326?style=for-the-badge&logo=Gitlab&logoColor=orange" alt="Source on GitLab.com"></a> <a href="https://codeberg.org/ruby-oauth/oauth2"><img src="https://img.shields.io/badge/CodeBerg-4893CC?style=for-the-badge&logo=CodeBerg&logoColor=blue" alt="Source on CodeBerg.org"></a> <a href="https://github.com/ruby-oauth/oauth2"><img src="https://img.shields.io/badge/GitHub-238636?style=for-the-badge&logo=Github&logoColor=green" alt="Source on Github.com"></a> <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"><img src="https://img.shields.io/badge/KLOC-0.519-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue" alt="The best SHA: dQw4w9WgXcQ!"></a>
</td>
</tr>
<tr>
<td>Documentation</td>
<td>
<a href="https://groups.google.com/g/oauth-ruby"><img src="https://img.shields.io/badge/google-group-0093D0.svg?style=for-the-badge&logo=google&logoColor=orange" alt="Discussion"></a> <a href="http://rubydoc.info/gems/oauth2"><img src="https://img.shields.io/badge/RubyDoc-Current_Release-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white" alt="Current release on RubyDoc.info"></a> <a href="https://oauth2.galtzo.com"><img src="https://img.shields.io/badge/YARD_on_Galtzo.com-HEAD-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white" alt="YARD on Galtzo.com"></a> <a href="http://www.railsbling.com/tags/oauth2"><img src="https://img.shields.io/badge/blog-railsbling-0093D0.svg?style=for-the-badge&logo=rubyonrails&logoColor=orange" alt="Maintainer Blog"></a> <a href="https://gitlab.com/ruby-oauth/oauth2/-/wikis/home"><img src="https://img.shields.io/badge/wiki-examples-943CD2.svg?style=for-the-badge&logo=Wiki&logoColor=white" alt="Wiki"></a>
</td>
</tr>
<tr>
<td>Compliance</td>
<td>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-259D6C.svg" alt="License: MIT"></a> <a href="https://www.ilo.org/declaration/lang--en/index.htm"><img src="https://img.shields.io/badge/ILO_Fundamental_Principles-%E2%9C%93-259D6C.svg?style=flat" alt="📄ilo-declaration-img"></a> <a href="file.SECURITY.html" title="<img src="https://img.shields.io/badge/security-policy-259D6C.svg?style=flat" alt="Security Policy">"><img src="https://img.shields.io/badge/security-policy-259D6C.svg?style=flat" alt="Security Policy"></a> <a href="file.CODE_OF_CONDUCT.html" title="<img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1">"><img src="https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg" alt="Contributor Covenant 2.1"></a> <a href="https://semver.org/spec/v2.0.0.html"><img src="https://img.shields.io/badge/semver-2.0.0-259D6C.svg?style=flat" alt="SemVer 2.0.0"></a>
</td>
</tr>
<tr>
<td>Style</td>
<td>
<a href="https://github.com/rubocop-lts/rubocop-lts"><img src="https://img.shields.io/badge/code_style_%26_linting-rubocop--lts-34495e.svg?plastic&logo=ruby&logoColor=white" alt="Enforced Code Style Linter"></a> <a href="https://keepachangelog.com/en/1.0.0/"><img src="https://img.shields.io/badge/keep--a--changelog-1.0.0-34495e.svg?style=flat" alt="Keep-A-Changelog 1.0.0"></a> <a href="https://gitmoji.dev"><img src="https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square" alt="Gitmoji Commits"></a> <a href="https://github.com/appraisal-rb/appraisal2"><img src="https://img.shields.io/badge/appraised_by-appraisal2-34495e.svg?plastic&logo=ruby&logoColor=white" alt="Compatibility appraised by: appraisal2"></a>
</td>
</tr>
<tr>
<td>Support</td>
<td>
<a href="https://discord.gg/3qme4XHNKN"><img src="https://img.shields.io/discord/1373797679469170758?style=for-the-badge" alt="Live Chat on Discord"></a> <a href="https://www.upwork.com/freelancers/~014942e9b056abdf86?mp_source=share"><img src="https://img.shields.io/badge/UpWork-13544E?style=for-the-badge&logo=Upwork&logoColor=white" alt="Get help from me on Upwork"></a> <a href="https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github"><img src="https://img.shields.io/badge/CodeMentor-Get_Help-1abc9c?style=for-the-badge&logo=CodeMentor&logoColor=white" alt="Get help from me on Codementor"></a>
</td>
</tr>
<tr>
<td>Maintainer 🎖️</td>
<td>
<a href="http://www.linkedin.com/in/peterboling"><img src="https://img.shields.io/badge/PeterBoling-LinkedIn-0B66C2?style=flat&logo=newjapanprowrestling" alt="Follow Me on LinkedIn"></a> <a href="https://ruby.social/@galtzo"><img src="https://img.shields.io/mastodon/follow/109447111526622197?domain=https%3A%2F%2Fruby.social&style=flat&logo=mastodon&label=Ruby%20%40galtzo" alt="Follow Me on Ruby.Social"></a> <a href="https://bsky.app/profile/galtzo.com"><img src="https://img.shields.io/badge/@galtzo.com-0285FF?style=flat&logo=bluesky&logoColor=white" alt="Follow Me on Bluesky"></a> <a href="http://www.railsbling.com/contact"><img src="https://img.shields.io/badge/Contact-Maintainer-0093D0.svg?style=flat&logo=rubyonrails&logoColor=red" alt="Contact Maintainer"></a> <a href="https://dev.to/galtzo"><img src="https://img.shields.io/badge/dev.to-0A0A0A?style=flat&logo=devdotto&logoColor=white" alt="My technical writing"></a>
</td>
</tr>
<tr>
<td>
<code>...</code> 💖</td>
<td>
<a href="https://wellfound.com/u/peter-boling/u/peter-boling"><img src="https://img.shields.io/badge/peter--boling-orange?style=flat&logo=wellfound" alt="Find Me on WellFound:"></a> <a href="https://www.crunchbase.com/person/peter-boling"><img src="https://img.shields.io/badge/peter--boling-purple?style=flat&logo=crunchbase" alt="Find Me on CrunchBase"></a> <a href="https://linktr.ee/galtzo"><img src="https://img.shields.io/badge/galtzo-purple?style=flat&logo=linktree" alt="My LinkTree"></a> <a href="https://about.me/peter.boling"><img src="https://img.shields.io/badge/about.me-0A0A0A?style=flat&logo=aboutme&logoColor=white" alt="More About Me"></a> <a href="https://codeberg.org/pboling">🧊</a> <a href="https://github.org/pboling">🐙</a> <a href="https://sr.ht/~galtzo/">🛖</a> <a href="https://gitlab.com/pboling">🧪</a>
</td>
</tr>
</tbody>
</table>
<h3 id="compatibility">Compatibility</h3>
<ul>
<li>Operating Systems: Linux, MacOS, Windows</li>
<li>MRI Ruby @ v2.3, v2.4, v2.5, v2.6, v2.7, v3.0, v3.1, v3.2, v3.3, v3.4, HEAD
<ul>
<li>NOTE: This gem will still install on ruby v2.2, but vanilla GitHub Actions no longer supports testing against it, so YMMV.</li>
</ul>
</li>
<li>JRuby @ v9.2, v9.3, v9.4, v10.0, HEAD</li>
<li>TruffleRuby @ v23.1, v24.1, HEAD</li>
<li>gem <code>faraday</code> @ v0, v1, v2, HEAD ⏩️ <a href="https://github.com/lostisland/faraday">lostisland/faraday</a>
</li>
<li>gem <code>jwt</code> @ v1, v2, v3, HEAD ⏩️ <a href="https://github.com/jwt/ruby-jwt">jwt/ruby-jwt</a>
</li>
<li>gem <code>logger</code> @ v1.2, v1.5, v1.7, HEAD ⏩️ <a href="https://github.com/ruby/logger">ruby/logger</a>
</li>
<li>gem <code>multi_xml</code> @ v0.5, v0.6, v0.7, HEAD ⏩️ <a href="https://github.com/sferik/multi_xml">sferik/multi_xml</a>
</li>
<li>gem <code>rack</code> @ v1.2, v1.6, v2, v3, HEAD ⏩️ <a href="https://github.com/rack/rack">rack/rack</a>
</li>
<li>gem <code>snaky_hash</code> @ v2, HEAD ⏩️ <a href="https://gitlab.com/ruby-oauth/snaky_hash">ruby-oauth/snaky_hash</a>
</li>
<li>gem <code>version_gem</code> @ v1, HEAD ⏩️ <a href="https://gitlab.com/ruby-oauth/version_gem">ruby-oauth/version_gem</a>
</li>
</ul>
<p>The last two were extracted from this gem. They are part of the <code>ruby-oauth</code> org,<br>
and are developed in tight collaboration with this gem.</p>
<p>Also, where reasonable, tested against the runtime dependencies of those dependencies:</p>
<ul>
<li>gem <code>hashie</code> @ v0, v1, v2, v3, v4, v5, HEAD ⏩️ <a href="https://github.com/hashie/hashie">hashie/hashie</a>
</li>
</ul>
<h4 id="upgrading-runtime-gem-dependencies">Upgrading Runtime Gem Dependencies</h4>
<p>This project sits underneath a large portion of the authorization systems on the internet.<br>
According to GitHub’s project tracking, which I believe only reports on public projects,<br>
<a href="https://github.com/ruby-oauth/oauth2/network/dependents">100,000+ projects</a>, and<br>
<a href="https://github.com/ruby-oauth/oauth2/network/dependents?dependent_type=PACKAGE">500+ packages</a> depend on this project.</p>
<p>That means it is painful for the Ruby community when this gem forces updates to its runtime dependencies.</p>
<p>As a result, great care, and a lot of time, have been invested to ensure this gem is working with all the<br>
leading versions per each minor version of Ruby of all the runtime dependencies it can install with.</p>
<p>What does that mean specifically for the runtime dependencies?</p>
<p>We have 100% test coverage of lines and branches, and this test suite runs across a large matrix<br>
covering the latest patch for each of the following minor versions:</p>
<table>
<thead>
<tr>
<th>🚚 <em>Amazing</em> test matrix was brought to you by</th>
<th>🔎 appraisal2 🔎</th>
</tr>
</thead>
<tbody>
<tr>
<td>👟 Check it out!</td>
<td>✨ <a href="https://github.com/appraisal-rb/appraisal2">github.com/appraisal-rb/appraisal2</a> ✨</td>
</tr>
</tbody>
</table>
<h4 id="you-should-upgrade-this-gem-with-confidence">You should upgrade this gem with confidence*.</h4>
<ul>
<li>This gem follows a <em>strict & correct</em> (according to the maintainer of SemVer; <a href="#-is-platform-support-part-of-the-public-api">more info</a>) interpretation of SemVer.
<ul>
<li>Dropping support for <strong>any</strong> of the runtime dependency versions above will be a major version bump.</li>
<li>If you aren’t on one of the minor versions above, make getting there a priority.</li>
</ul>
</li>
<li>You should upgrade the dependencies of this gem with confidence*.</li>
<li>Please do upgrade, and then, when it goes smooth as butter <a href="https://github.com/sponsors/pboling">please sponsor me</a>. Thanks!</li>
</ul>
<p>* MIT license; The only guarantees I make are for <a href="#enterprise-support">enterprise support</a>.</p>
<details>
<summary>Standard Library Dependencies</summary>
The various versions of each are tested via the Ruby test matrix, along with whatever Ruby includes them.
* base64
* cgi
* json
* time
* logger (removed from stdlib in Ruby 3.5 so added as runtime dependency in v2.0.10)
If you use a gem version of a core Ruby library it should work fine!
</details>
<h3 id="federated-dvcs">Federated DVCS</h3>
<details>
<summary>Find this repo on other forges (Coming soon!)</summary>
| Federated [DVCS][💎d-in-dvcs] Repository | Status | Issues | PRs | Wiki | CI | Discussions |
|-----------------------------------------------|-----------------------------------------------------------------------|---------------------------|--------------------------|---------------------------|--------------------------|------------------------------|
| 🧪 [ruby-oauth/oauth2 on GitLab][📜src-gl] | The Truth | [💚][🤝gl-issues] | [💚][🤝gl-pulls] | [💚][📜wiki] | 🏀 Tiny Matrix | ➖ |
| 🧊 [ruby-oauth/oauth2 on CodeBerg][📜src-cb] | An Ethical Mirror ([Donate][🤝cb-donate]) | [💚][🤝cb-issues] | [💚][🤝cb-pulls] | ➖ | ⭕️ No Matrix | ➖ |
| 🐙 [ruby-oauth/oauth2 on GitHub][📜src-gh] | Another Mirror | [💚][🤝gh-issues] | [💚][🤝gh-pulls] | ➖ | 💯 Full Matrix | [💚][gh-discussions] |
| 🤼 [OAuth Ruby Google Group][⛳gg-discussions] | "Active" | ➖ | ➖ | ➖ | ➖ | [💚][⛳gg-discussions] |
| 🎮️ [Discord Server][✉️discord-invite] | [![Live Chat on Discord][✉️discord-invite-img-ftb]][✉️discord-invite] | [Let's][✉️discord-invite] | [talk][✉️discord-invite] | [about][✉️discord-invite] | [this][✉️discord-invite] | [library!][✉️discord-invite] |
</details>
<h3 id="enterprise-support-">Enterprise Support <a href="https://tidelift.com/subscription/pkg/rubygems-oauth2?utm_source=rubygems-oauth2&utm_medium=referral&utm_campaign=readme"><img src="https://tidelift.com/badges/package/rubygems/oauth2" alt="Tidelift"></a>
</h3>
<p>Available as part of the Tidelift Subscription.</p>
<details>
<summary>Need enterprise-level guarantees?</summary>
The maintainers of this and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
[![Get help from me on Tidelift][🏙️entsup-tidelift-img]][🏙️entsup-tidelift]
- 💡Subscribe for support guarantees covering _all_ your FLOSS dependencies
- 💡Tidelift is part of [Sonar][🏙️entsup-tidelift-sonar]
- 💡Tidelift pays maintainers to maintain the software you depend on!<br>📊`@`Pointy Haired Boss: An [enterprise support][🏙️entsup-tidelift] subscription is "[never gonna let you down][🧮kloc]", and *supports* open source maintainers
Alternatively:
- [![Live Chat on Discord][✉️discord-invite-img-ftb]][✉️discord-invite]
- [![Get help from me on Upwork][👨🏼🏫expsup-upwork-img]][👨🏼🏫expsup-upwork]
- [![Get help from me on Codementor][👨🏼🏫expsup-codementor-img]][👨🏼🏫expsup-codementor]
</details>
<h2 id="-release-documentation">🚀 Release Documentation</h2>
<h3 id="version-20x">Version 2.0.x</h3>
<details>
<summary>2.0.x CHANGELOG and README</summary>
| Version | Release Date | CHANGELOG | README |
|---------|--------------|---------------------------------------|---------------------------------|
| 2.0.13 | 2025-08-30 | [v2.0.13 CHANGELOG][2.0.13-changelog] | [v2.0.13 README][2.0.13-readme] |
| 2.0.12 | 2025-05-31 | [v2.0.12 CHANGELOG][2.0.12-changelog] | [v2.0.12 README][2.0.12-readme] |
| 2.0.11 | 2025-05-23 | [v2.0.11 CHANGELOG][2.0.11-changelog] | [v2.0.11 README][2.0.11-readme] |
| 2.0.10 | 2025-05-17 | [v2.0.10 CHANGELOG][2.0.10-changelog] | [v2.0.10 README][2.0.10-readme] |
| 2.0.9 | 2022-09-16 | [v2.0.9 CHANGELOG][2.0.9-changelog] | [v2.0.9 README][2.0.9-readme] |
| 2.0.8 | 2022-09-01 | [v2.0.8 CHANGELOG][2.0.8-changelog] | [v2.0.8 README][2.0.8-readme] |
| 2.0.7 | 2022-08-22 | [v2.0.7 CHANGELOG][2.0.7-changelog] | [v2.0.7 README][2.0.7-readme] |
| 2.0.6 | 2022-07-13 | [v2.0.6 CHANGELOG][2.0.6-changelog] | [v2.0.6 README][2.0.6-readme] |
| 2.0.5 | 2022-07-07 | [v2.0.5 CHANGELOG][2.0.5-changelog] | [v2.0.5 README][2.0.5-readme] |
| 2.0.4 | 2022-07-01 | [v2.0.4 CHANGELOG][2.0.4-changelog] | [v2.0.4 README][2.0.4-readme] |
| 2.0.3 | 2022-06-28 | [v2.0.3 CHANGELOG][2.0.3-changelog] | [v2.0.3 README][2.0.3-readme] |
| 2.0.2 | 2022-06-24 | [v2.0.2 CHANGELOG][2.0.2-changelog] | [v2.0.2 README][2.0.2-readme] |
| 2.0.1 | 2022-06-22 | [v2.0.1 CHANGELOG][2.0.1-changelog] | [v2.0.1 README][2.0.1-readme] |
| 2.0.0 | 2022-06-21 | [v2.0.0 CHANGELOG][2.0.0-changelog] | [v2.0.0 README][2.0.0-readme] |
</details>
<h3 id="older-releases">Older Releases</h3>
<details>
<summary>1.4.x CHANGELOGs and READMEs</summary>
| Version | Release Date | CHANGELOG | README |
|---------|--------------|---------------------------------------|---------------------------------|
| 1.4.11 | Sep 16, 2022 | [v1.4.11 CHANGELOG][1.4.11-changelog] | [v1.4.11 README][1.4.11-readme] |
| 1.4.10 | Jul 1, 2022 | [v1.4.10 CHANGELOG][1.4.10-changelog] | [v1.4.10 README][1.4.10-readme] |
| 1.4.9 | Feb 20, 2022 | [v1.4.9 CHANGELOG][1.4.9-changelog] | [v1.4.9 README][1.4.9-readme] |
| 1.4.8 | Feb 18, 2022 | [v1.4.8 CHANGELOG][1.4.8-changelog] | [v1.4.8 README][1.4.8-readme] |
| 1.4.7 | Mar 19, 2021 | [v1.4.7 CHANGELOG][1.4.7-changelog] | [v1.4.7 README][1.4.7-readme] |
| 1.4.6 | Mar 19, 2021 | [v1.4.6 CHANGELOG][1.4.6-changelog] | [v1.4.6 README][1.4.6-readme] |
| 1.4.5 | Mar 18, 2021 | [v1.4.5 CHANGELOG][1.4.5-changelog] | [v1.4.5 README][1.4.5-readme] |
| 1.4.4 | Feb 12, 2020 | [v1.4.4 CHANGELOG][1.4.4-changelog] | [v1.4.4 README][1.4.4-readme] |
| 1.4.3 | Jan 29, 2020 | [v1.4.3 CHANGELOG][1.4.3-changelog] | [v1.4.3 README][1.4.3-readme] |
| 1.4.2 | Oct 1, 2019 | [v1.4.2 CHANGELOG][1.4.2-changelog] | [v1.4.2 README][1.4.2-readme] |
| 1.4.1 | Oct 13, 2018 | [v1.4.1 CHANGELOG][1.4.1-changelog] | [v1.4.1 README][1.4.1-readme] |
| 1.4.0 | Jun 9, 2017 | [v1.4.0 CHANGELOG][1.4.0-changelog] | [v1.4.0 README][1.4.0-readme] |
</details>
<details>
<summary>1.3.x Readmes</summary>
| Version | Release Date | Readme |
|---------|--------------|--------------------------------------------------------------|
| 1.3.1 | Mar 3, 2017 | https://gitlab.com/ruby-oauth/oauth2/-/blob/v1.3.1/README.md |
| 1.3.0 | Dec 27, 2016 | https://gitlab.com/ruby-oauth/oauth2/-/blob/v1.3.0/README.md |
</details>
<details>
<summary>≤= 1.2.x Readmes (2016 and before)</summary>
| Version | Release Date | Readme |
|---------|--------------|--------------------------------------------------------------|
| 1.2.0 | Jun 30, 2016 | https://gitlab.com/ruby-oauth/oauth2/-/blob/v1.2.0/README.md |
| 1.1.0 | Jan 30, 2016 | https://gitlab.com/ruby-oauth/oauth2/-/blob/v1.1.0/README.md |
| 1.0.0 | May 23, 2014 | https://gitlab.com/ruby-oauth/oauth2/-/blob/v1.0.0/README.md |
| < 1.0.0 | Find here | https://gitlab.com/ruby-oauth/oauth2/-/tags |
</details>
<h2 id="-installation">✨ Installation</h2>
<p>Install the gem and add to the application’s Gemfile by executing:</p>
<pre class="code language-console"><code class="language-console">bundle add oauth2
</code></pre>
<p>If bundler is not being used to manage dependencies, install the gem by executing:</p>
<pre class="code language-console"><code class="language-console">gem install oauth2
</code></pre>
<h3 id="-secure-installation">🔒 Secure Installation</h3>
<details>
<summary>For Medium or High Security Installations</summary>
This gem is cryptographically signed, and has verifiable [SHA-256 and SHA-512][💎SHA_checksums] checksums by
[stone_checksums][💎stone_checksums]. Be sure the gem you install hasn’t been tampered with
by following the instructions below.
Add my public key (if you haven’t already, expires 2045-04-29) as a trusted certificate:
```console
gem cert --add <(curl -Ls https://raw.github.com/galtzo-floss/certs/main/pboling.pem)
```
You only need to do that once. Then proceed to install with:
```console
gem install oauth2 -P MediumSecurity
```
The `MediumSecurity` trust profile will verify signed gems, but allow the installation of unsigned dependencies.
This is necessary because not all of `oauth2`’s dependencies are signed, so we cannot use `HighSecurity`.
If you want to up your security game full-time:
```console
bundle config set --global trust-policy MediumSecurity
```
NOTE: Be prepared to track down certs for signed gems and add them the same way you added mine.
</details>
<h2 id="what-is-new-for-v20">What is new for v2.0?</h2>
<ul>
<li>Works with Ruby versions >= 2.2</li>
<li>Drop support for the expired MAC Draft (all versions)</li>
<li>Support IETF rfc7515 JSON Web Signature - JWS (since v2.0.12)
<ul>
<li>Support JWT <code>kid</code> for key discovery and management</li>
</ul>
</li>
<li>Support IETF rfc7523 JWT Bearer Tokens (since v2.0.0)</li>
<li>Support IETF rfc7231 Relative Location in Redirect (since v2.0.0)</li>
<li>Support IETF rfc6749 Don’t set oauth params when nil (since v2.0.0)</li>
<li>Support IETF rfc7009 Token Revocation (since v2.0.10, updated in v2.0.13 to support revocation via URL-encoded parameters)</li>
<li>Support <a href="https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication">OIDC 1.0 Private Key JWT</a>; based on the OAuth JWT assertion specification <a href="https://tools.ietf.org/html/rfc7523">(RFC 7523)</a>
</li>
<li>Support new formats, including from <a href="http://jsonapi.org/format/">jsonapi.org</a>: <code>application/vdn.api+json</code>, <code>application/vnd.collection+json</code>, <code>application/hal+json</code>, <code>application/problem+json</code>
</li>
<li>Adds option to <code>OAuth2::Client#get_token</code>:
<ul>
<li>
<code>:access_token_class</code> (<code>AccessToken</code>); user specified class to use for all calls to <code>get_token</code>
</li>
</ul>
</li>
<li>Adds option to <code>OAuth2::AccessToken#initialize</code>:
<ul>
<li>
<code>:expires_latency</code> (<code>nil</code>); number of seconds by which AccessToken validity will be reduced to offset latency</li>
</ul>
</li>
<li>By default, keys are transformed to snake case.
<ul>
<li>Original keys will still work as previously, in most scenarios, thanks to <a href="https://gitlab.com/ruby-oauth/snaky_hash">snaky_hash</a> gem.</li>
<li>However, this is a <em>breaking</em> change if you rely on <code>response.parsed.to_h</code> to retain the original case, and the original wasn’t snake case, as the keys in the result will be snake case.</li>
<li>As of version 2.0.4 you can turn key transformation off with the <code>snaky: false</code> option.</li>
</ul>
</li>
<li>By default, the <code>:auth_scheme</code> is now <code>:basic_auth</code> (instead of <code>:request_body</code>)
<ul>
<li>Third-party strategies and gems may need to be updated if a provider was requiring client id/secret in the request body</li>
</ul>
</li>
<li><a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/CHANGELOG.md#200-2022-06-21-tag">… A lot more</a></li>
</ul>
<h2 id="compatibility-1">Compatibility</h2>
<p>Targeted ruby compatibility is non-EOL versions of Ruby, currently 3.2, 3.3, and 3.4.<br>
Compatibility is further distinguished as “Best Effort Support” or “Incidental Support” for older versions of Ruby.<br>
This gem will install on Ruby versions >= v2.2 for 2.x releases.<br>
See <code>1-4-stable</code> branch for older rubies.</p>
<details>
<summary>Ruby Engine Compatibility Policy</summary>
This gem is tested against MRI, JRuby, and Truffleruby.
Each of those has varying versions that target a specific version of MRI Ruby.
This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below.
If you would like to add support for additional engines,
see [gemfiles/README.md](gemfiles/README.md), then submit a PR to the correct maintenance branch as according to the table below.
</details>
<details>
<summary>Ruby Version Compatibility Policy</summary>
If something doesn't work on one of these interpreters, it's a bug.
This library may inadvertently work (or seem to work) on other Ruby
implementations, however support will only be provided for the versions listed
above.
If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all tests
run and pass on that implementation. When something breaks on your
implementation, you will be responsible for providing patches in a timely
fashion. If critical issues for a particular implementation exist at the time
of a major release, support for that Ruby version may be dropped.
</details>
<table>
<thead>
<tr>
<th style="text-align: left"> </th>
<th>Ruby OAuth2 Version</th>
<th>Maintenance Branch</th>
<th>Targeted Support</th>
<th>Best Effort Support</th>
<th>Incidental Support</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">1️⃣</td>
<td>2.0.x</td>
<td><code>main</code></td>
<td>3.2, 3.3, 3.4</td>
<td>2.5, 2.6, 2.7, 3.0, 3.1</td>
<td>2.2, 2.3, 2.4</td>
</tr>
<tr>
<td style="text-align: left">2️⃣</td>
<td>1.4.x</td>
<td><code>1-4-stable</code></td>
<td>3.2, 3.3, 3.4</td>
<td>2.5, 2.6, 2.7, 3.0, 3.1</td>
<td>1.9, 2.0, 2.1, 2.2, 2.3, 2.4</td>
</tr>
<tr>
<td style="text-align: left">3️⃣</td>
<td>older</td>
<td>N/A</td>
<td>Best of luck to you!</td>
<td>Please upgrade!</td>
<td> </td>
</tr>
</tbody>
</table>
<p>NOTE: The 1.4 series will only receive critical security updates.<br>
See <a href="file.SECURITY.html" title="SECURITY.md">SECURITY.md</a>.</p>
<h2 id="️-configuration">⚙️ Configuration</h2>
<p>You can turn on additional warnings.</p>
<pre class="code language-ruby"><code class="language-ruby">OAuth2.configure do |config|
# Turn on a warning like:
# OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key
config.silence_extra_tokens_warning = false # default: true
# Set to true if you want to also show warnings about no tokens
config.silence_no_tokens_warning = false # default: true,
end
</code></pre>
<p>The “extra tokens” problem comes from ambiguity in the spec about which token is the right token.<br>
Some OAuth 2.0 standards legitimately have multiple tokens.<br>
You may need to subclass <code>OAuth2::AccessToken</code>, or write your own custom alternative to it, and pass it in.<br>
Specify your custom class with the <code>access_token_class</code> option.</p>
<p>If you only need one token you can, as of v2.0.10,<br>
specify the exact token name you want to extract via the <code>OAuth2::AccessToken</code> using<br>
the <code>token_name</code> option.</p>
<p>You’ll likely need to do some source diving.<br>
This gem has 100% test coverage for lines and branches, so the specs are a great place to look for ideas.<br>
If you have time and energy please contribute to the documentation!</p>
<h2 id="-basic-usage">🔧 Basic Usage</h2>
<h3 id="authorize_url-and-token_url-are-on-site-root-just-works">
<code>authorize_url</code> and <code>token_url</code> are on site root (Just Works!)</h3>
<pre class="code language-ruby"><code class="language-ruby">require "oauth2"
client = OAuth2::Client.new("client_id", "client_secret", site: "https://example.org")
# => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
client.auth_code.authorize_url(redirect_uri: "http://localhost:8080/oauth2/callback")
# => "https://example.org/oauth/authorize?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
access = client.auth_code.get_token("authorization_code_value", redirect_uri: "http://localhost:8080/oauth2/callback", headers: {"Authorization" => "Basic some_password"})
response = access.get("/api/resource", params: {"query_foo" => "bar"})
response.class.name
# => OAuth2::Response
</code></pre>
<h3 id="relative-authorize_url-and-token_url-not-on-site-root-just-works">Relative <code>authorize_url</code> and <code>token_url</code> (Not on site root, Just Works!)</h3>
<p>In above example, the default Authorization URL is <code>oauth/authorize</code> and default Access Token URL is <code>oauth/token</code>, and, as they are missing a leading <code>/</code>, both are relative.</p>
<pre class="code language-ruby"><code class="language-ruby">client = OAuth2::Client.new("client_id", "client_secret", site: "https://example.org/nested/directory/on/your/server")
# => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
client.auth_code.authorize_url(redirect_uri: "http://localhost:8080/oauth2/callback")
# => "https://example.org/nested/directory/on/your/server/oauth/authorize?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
</code></pre>
<h3 id="customize-authorize_url-and-token_url">Customize <code>authorize_url</code> and <code>token_url</code>
</h3>
<p>You can specify custom URLs for authorization and access token, and when using a leading <code>/</code> they will <em>not be relative</em>, as shown below:</p>
<pre class="code language-ruby"><code class="language-ruby">client = OAuth2::Client.new(
"client_id",
"client_secret",
site: "https://example.org/nested/directory/on/your/server",
authorize_url: "/jaunty/authorize/",
token_url: "/stirrups/access_token",
)
# => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
client.auth_code.authorize_url(redirect_uri: "http://localhost:8080/oauth2/callback")
# => "https://example.org/jaunty/authorize/?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"
client.class.name
# => OAuth2::Client
</code></pre>
<h3 id="snake_case-and-indifferent-access-in-responseparsed">snake_case and indifferent access in Response#parsed</h3>
<pre class="code language-ruby"><code class="language-ruby">response = access.get("/api/resource", params: {"query_foo" => "bar"})
# Even if the actual response is CamelCase. it will be made available as snaky:
JSON.parse(response.body) # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
response.parsed # => {"access_token"=>"aaaaaaaa", "additional_data"=>"additional"}
response.parsed.access_token # => "aaaaaaaa"
response.parsed[:access_token] # => "aaaaaaaa"
response.parsed.additional_data # => "additional"
response.parsed[:additional_data] # => "additional"
response.parsed.class.name # => SnakyHash::StringKeyed (from snaky_hash gem)
</code></pre>
<h4 id="serialization">Serialization</h4>
<p>As of v2.0.11, if you need to serialize the parsed result, you can!</p>
<p>There are two ways to do this, globally, or discretely. The discrete way is recommended.</p>
<h5 id="global-serialization-config">Global Serialization Config</h5>
<p>Globally configure <code>SnakyHash::StringKeyed</code> to use the serializer. Put this in your code somewhere reasonable (like an initializer for Rails).</p>
<pre class="code language-ruby"><code class="language-ruby">SnakyHash::StringKeyed.class_eval do
extend SnakyHash::Serializer
end
</code></pre>
<h5 id="discrete-serialization-config">Discrete Serialization Config</h5>
<p>Discretely configure a custom Snaky Hash class to use the serializer.</p>
<pre class="code language-ruby"><code class="language-ruby">class MySnakyHash < SnakyHash::StringKeyed
# Give this hash class `dump` and `load` abilities!
extend SnakyHash::Serializer
end
# And tell your client to use the custom class in each call:
client = OAuth2::Client.new("client_id", "client_secret", site: "https://example.org/oauth2")
token = client.get_token({snaky_hash_klass: MySnakyHash})
</code></pre>
<h5 id="serialization-extensions">Serialization Extensions</h5>
<p>These extensions work regardless of whether you used the global or discrete config above.</p>
<p>There are a few hacks you may need in your class to support Ruby < 2.4.2 or < 2.6.<br>
They are likely not needed if you are on a newer Ruby.<br>
See <a href="https://github.com/ruby-oauth/oauth2/blob/main/spec/oauth2/response_spec.rb">response_spec.rb</a> if you need to study the hacks for older Rubies.</p>
<pre class="code language-ruby"><code class="language-ruby">class MySnakyHash < SnakyHash::StringKeyed
# Give this hash class `dump` and `load` abilities!
extend SnakyHash::Serializer
#### Serialization Extentions
#
# Act on the non-hash values (including the values of hashes) as they are dumped to JSON
# In other words, this retains nested hashes, and only the deepest leaf nodes become bananas.
# WARNING: This is a silly example!
dump_value_extensions.add(:to_fruit) do |value|
"banana" # => Make values "banana" on dump
end
# Act on the non-hash values (including the values of hashes) as they are loaded from the JSON dump
# In other words, this retains nested hashes, and only the deepest leaf nodes become ***.
# WARNING: This is a silly example!
load_value_extensions.add(:to_stars) do |value|
"***" # Turn dumped bananas into *** when they are loaded
end
# Act on the entire hash as it is prepared for dumping to JSON
# WARNING: This is a silly example!
dump_hash_extensions.add(:to_cheese) do |value|
if value.is_a?(Hash)
value.transform_keys do |key|
split = key.split("_")
first_word = split[0]
key.sub(first_word, "cheese")
end
else
value
end
end
# Act on the entire hash as it is loaded from the JSON dump
# WARNING: This is a silly example!
load_hash_extensions.add(:to_pizza) do |value|
if value.is_a?(Hash)
res = klass.new
value.keys.each_with_object(res) do |key, result|
split = key.split("_")
last_word = split[-1]
new_key = key.sub(last_word, "pizza")
result[new_key] = value[key]
end
res
else
value
end
end
end
</code></pre>
<p>See <a href="https://github.com/ruby-oauth/oauth2/blob/main/spec/oauth2/response_spec.rb">response_spec.rb</a>, or the <a href="https://gitlab.com/ruby-oauth/snaky_hash">ruby-oauth/snaky_hash</a> gem for more ideas.</p>
<h4 id="prefer-camelcase-over-snake_case--snaky-false">Prefer camelCase over snake_case? => snaky: false</h4>
<pre class="code language-ruby"><code class="language-ruby">response = access.get("/api/resource", params: {"query_foo" => "bar"}, snaky: false)
JSON.parse(response.body) # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
response.parsed # => {"accessToken"=>"aaaaaaaa", "additionalData"=>"additional"}
response.parsed["accessToken"] # => "aaaaaaaa"
response.parsed["additionalData"] # => "additional"
response.parsed.class.name # => Hash (just, regular old Hash)
</code></pre>
<details>
<summary>Debugging & Logging</summary>
Set an environment variable as per usual (e.g. with [dotenv](https://github.com/bkeepers/dotenv)).
```ruby
# will log both request and response, including bodies
ENV["OAUTH_DEBUG"] = "true"
```
By default, debug output will go to `$stdout`. This can be overridden when
initializing your OAuth2::Client.
```ruby
require "oauth2"
client = OAuth2::Client.new(
"client_id",
"client_secret",
site: "https://example.org",
logger: Logger.new("example.log", "weekly"),
)
```
</details>
<h3 id="oauth2response">OAuth2::Response</h3>
<p>The <code>AccessToken</code> methods <code>#get</code>, <code>#post</code>, <code>#put</code> and <code>#delete</code> and the generic <code>#request</code><br>
will return an instance of the #OAuth2::Response class.</p>
<p>This instance contains a <code>#parsed</code> method that will parse the response body and<br>
return a Hash-like <a href="https://gitlab.com/ruby-oauth/snaky_hash/-/blob/main/lib/snaky_hash/string_keyed.rb"><code>SnakyHash::StringKeyed</code></a> if the <code>Content-Type</code> is <code>application/x-www-form-urlencoded</code> or if<br>
the body is a JSON object. It will return an Array if the body is a JSON<br>
array. Otherwise, it will return the original body string.</p>
<p>The original response body, headers, and status can be accessed via their<br>
respective methods.</p>
<h3 id="oauth2accesstoken">OAuth2::AccessToken</h3>
<p>If you have an existing Access Token for a user, you can initialize an instance<br>
using various class methods including the standard new, <code>from_hash</code> (if you have<br>
a hash of the values), or <code>from_kvform</code> (if you have an<br>
<code>application/x-www-form-urlencoded</code> encoded string of the values).</p>
<h3 id="oauth2error">OAuth2::Error</h3>
<p>On 400+ status code responses, an <code>OAuth2::Error</code> will be raised. If it is a<br>
standard OAuth2 error response, the body will be parsed and <code>#code</code> and <code>#description</code> will contain the values provided from the error and<br>
<code>error_description</code> parameters. The <code>#response</code> property of <code>OAuth2::Error</code> will<br>
always contain the <code>OAuth2::Response</code> instance.</p>
<p>If you do not want an error to be raised, you may use <code>:raise_errors => false</code><br>
option on initialization of the client. In this case the <code>OAuth2::Response</code><br>
instance will be returned as usual and on 400+ status code responses, the<br>
Response instance will contain the <code>OAuth2::Error</code> instance.</p>
<h3 id="authorization-grants">Authorization Grants</h3>
<p>Note on OAuth 2.1 (draft):</p>
<ul>
<li>PKCE is required for all OAuth clients using the authorization code flow (especially public clients). Implement PKCE in your app when required by your provider. See RFC 7636 and RFC 8252.</li>
<li>Redirect URIs must be compared using exact string matching by the Authorization Server.</li>
<li>The Implicit grant (response_type=token) and the Resource Owner Password Credentials grant are omitted from OAuth 2.1; they remain here for OAuth 2.0 compatibility but should be avoided for new apps.</li>
<li>Bearer tokens in the query string are omitted due to security risks; prefer Authorization header usage.</li>
<li>Refresh tokens for public clients must either be sender-constrained (e.g., DPoP/MTLS) or one-time use.</li>
<li>The definitions of public and confidential clients are simplified to refer only to whether the client has credentials.</li>
</ul>
<p>References:</p>
<ul>
<li>OAuth 2.1 draft: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-13</li>
<li>Aaron Parecki: https://aaronparecki.com/2019/12/12/21/its-time-for-oauth-2-dot-1</li>
<li>FusionAuth: https://fusionauth.io/blog/2020/04/15/whats-new-in-oauth-2-1</li>
<li>Okta: https://developer.okta.com/blog/2019/12/13/oauth-2-1-how-many-rfcs</li>
<li>Video: https://www.youtube.com/watch?v=g_aVPdwBTfw</li>
<li>Differences overview: https://fusionauth.io/learn/expert-advice/oauth/differences-between-oauth-2-oauth-2-1/</li>
</ul>
<p>Currently, the Authorization Code, Implicit, Resource Owner Password Credentials, Client Credentials, and Assertion<br>
authentication grant types have helper strategy classes that simplify client<br>
use. They are available via the <a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/lib/oauth2/strategy/auth_code.rb"><code>#auth_code</code></a>,<br>
<a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/lib/oauth2/strategy/implicit.rb"><code>#implicit</code></a>,<br>
<a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/lib/oauth2/strategy/password.rb"><code>#password</code></a>,<br>
<a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/lib/oauth2/strategy/client_credentials.rb"><code>#client_credentials</code></a>, and<br>
<a href="https://gitlab.com/ruby-oauth/oauth2/-/blob/main/lib/oauth2/strategy/assertion.rb"><code>#assertion</code></a> methods respectively.</p>
<p>These aren’t full examples, but demonstrative of the differences between usage for each strategy.</p>
<pre class="code language-ruby"><code class="language-ruby">auth_url = client.auth_code.authorize_url(redirect_uri: "http://localhost:8080/oauth/callback")
access = client.auth_code.get_token("code_value", redirect_uri: "http://localhost:8080/oauth/callback")
auth_url = client.implicit.authorize_url(redirect_uri: "http://localhost:8080/oauth/callback")
# get the token params in the callback and
access = OAuth2::AccessToken.from_kvform(client, query_string)
access = client.password.get_token("username", "password")
access = client.client_credentials.get_token
# Client Assertion Strategy
# see: https://tools.ietf.org/html/rfc7523
claimset = {
iss: "http://localhost:3001",
aud: "http://localhost:8080/oauth2/token",
sub: "me@example.com",
exp: Time.now.utc.to_i + 3600,
}
assertion_params = [claimset, "HS256", "secret_key"]
access = client.assertion.get_token(assertion_params)
# The `access` (i.e. access token) is then used like so:
access.token # actual access_token string, if you need it somewhere
access.get("/api/stuff") # making api calls with access token
</code></pre>
<p>If you want to specify additional headers to be sent out with the<br>
request, add a ‘headers’ hash under ‘params’:</p>
<pre class="code language-ruby"><code class="language-ruby">access = client.auth_code.get_token("code_value", redirect_uri: "http://localhost:8080/oauth/callback", headers: {"Some" => "Header"})
</code></pre>
<p>You can always use the <code>#request</code> method on the <code>OAuth2::Client</code> instance to make<br>
requests for tokens for any Authentication grant type.</p>
<h2 id="-comprehensive-usage">📘 Comprehensive Usage</h2>
<h3 id="common-flows-end-to-end">Common Flows (end-to-end)</h3>
<ul>
<li>Authorization Code (server-side web app):</li>
</ul>
<pre class="code language-ruby"><code class="language-ruby">require "oauth2"
client = OAuth2::Client.new(
ENV["CLIENT_ID"],
ENV["CLIENT_SECRET"],
site: "https://provider.example.com",
redirect_uri: "https://my.app.example.com/oauth/callback",
)
# Step 1: redirect user to consent
state = SecureRandom.hex(16)
auth_url = client.auth_code.authorize_url(scope: "openid profile email", state: state)
# redirect_to auth_url
# Step 2: handle the callback
# params[:code], params[:state]
raise "state mismatch" unless params[:state] == state
access = client.auth_code.get_token(params[:code])
# Step 3: call APIs
profile = access.get("/api/v1/me").parsed
</code></pre>
<ul>
<li>Client Credentials (machine-to-machine):</li>
</ul>
<pre class="code language-ruby"><code class="language-ruby">client = OAuth2::Client.new(ENV["CLIENT_ID"], ENV["CLIENT_SECRET"], site: "https://provider.example.com")
access = client.client_credentials.get_token(audience: "https://api.example.com")
resp = access.get("/v1/things")
</code></pre>
<ul>
<li>Resource Owner Password (legacy; avoid when possible):</li>
</ul>
<pre class="code language-ruby"><code class="language-ruby">access = client.password.get_token("jdoe", "s3cret", scope: "read")
</code></pre>
<h4 id="examples">Examples</h4>
<details>
<summary>JHipster UAA (Spring Cloud) password grant example (legacy; avoid when possible)</summary>
```ruby
# This converts a Postman/Net::HTTP multipart token request to oauth2 gem usage.
# JHipster UAA typically exposes the token endpoint at /uaa/oauth/token.
# The original snippet included:
# - Basic Authorization header for the client (web_app:changeit)
# - X-XSRF-TOKEN header from a cookie (some deployments require it)
# - grant_type=password with username/password and client_id
# Using oauth2 gem, you don't need to build multipart bodies; the gem sends
# application/x-www-form-urlencoded as required by RFC 6749.
require "oauth2"
client = OAuth2::Client.new(
"web_app", # client_id
"changeit", # client_secret
site: "http://localhost:8080/uaa",
token_url: "/oauth/token", # absolute under site (or "oauth/token" relative)
auth_scheme: :basic_auth, # sends HTTP Basic Authorization header
)
# If your UAA requires an XSRF header for the token call, provide it as a header.
# Often this is not required for token endpoints, but if your gateway enforces it,
# obtain the value from the XSRF-TOKEN cookie and pass it here.
xsrf_token = ENV["X_XSRF_TOKEN"] # e.g., pulled from a prior set-cookie value
access = client.password.get_token(
"admin", # username
"admin", # password
headers: xsrf_token ? => xsrf_token : {},
# JHipster commonly also accepts/needs the client_id in the body; include if required:
# client_id: "web_app",
)
puts access.token
puts access.to_hash # full token response
```
Notes:
- Resource Owner Password Credentials (ROPC) is deprecated in OAuth 2.1 and discouraged. Prefer Authorization Code + PKCE.
- If your deployment strictly demands the X-XSRF-TOKEN header, first fetch it from an endpoint that sets the XSRF-TOKEN cookie (often "/" or a login page) and pass it to headers.
- For Basic auth, auth_scheme: :basic_auth handles the Authorization header; you do not need to base64-encode manually.
</details>
<h3 id="refresh-tokens">Refresh Tokens</h3>
<p>When the server issues a refresh_token, you can refresh manually or implement an auto-refresh wrapper.</p>
<ul>
<li>Manual refresh:</li>
</ul>
<pre class="code language-ruby"><code class="language-ruby">if access.expired?
access = access.refresh
end
</code></pre>