authproto 0.3.0.beta4 → 0.3.0.beta5

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +474 -311
  4. data/examples/basic_webapp/Gemfile +14 -0
  5. data/examples/{confidential_client → basic_webapp}/Gemfile.lock +1 -1
  6. data/examples/basic_webapp/README.md +300 -0
  7. data/examples/basic_webapp/app.rb +351 -0
  8. data/examples/basic_webapp/config/oauth-client-metadata.localhost.json +11 -0
  9. data/examples/basic_webapp/public/styles.css +346 -0
  10. data/examples/basic_webapp/scripts/generate_keys.rb +35 -0
  11. data/examples/basic_webapp/views/authorized.erb +48 -0
  12. data/examples/basic_webapp/views/index.erb +48 -0
  13. data/examples/{confidential_client → basic_webapp}/views/layout.erb +2 -2
  14. data/examples/bookmarks/Gemfile +16 -0
  15. data/examples/bookmarks/Gemfile.lock +158 -0
  16. data/examples/bookmarks/README.md +170 -0
  17. data/examples/bookmarks/Rakefile +23 -0
  18. data/examples/bookmarks/app/account.rb +16 -0
  19. data/examples/bookmarks/app/bookmark.rb +89 -0
  20. data/examples/bookmarks/app/init.rb +26 -0
  21. data/examples/bookmarks/app/oauth.rb +43 -0
  22. data/examples/bookmarks/app/server.rb +184 -0
  23. data/examples/bookmarks/config/oauth-client-metadata.localhost.json +11 -0
  24. data/examples/bookmarks/config/oauth-client-metadata.production.json +19 -0
  25. data/examples/bookmarks/config.ru +5 -0
  26. data/examples/bookmarks/db/migrate/20261107004141_create_bookmarks.rb +27 -0
  27. data/examples/bookmarks/db/schema.rb +33 -0
  28. data/examples/bookmarks/public/styles.css +59 -0
  29. data/examples/bookmarks/scripts/generate_keys.rb +35 -0
  30. data/examples/bookmarks/views/bookmarks.erb +86 -0
  31. data/examples/bookmarks/views/index.erb +17 -0
  32. data/examples/bookmarks/views/layout.erb +20 -0
  33. data/examples/minisky_console/Gemfile.lock +2 -2
  34. data/examples/minisky_console/README.md +29 -25
  35. data/examples/minisky_console/app.rb +3 -3
  36. data/examples/minisky_console/localhost.rb +5 -7
  37. data/examples/minisky_console/production.rb +6 -8
  38. data/lib/authproto/client.rb +413 -126
  39. data/lib/authproto/configuration.rb +1 -1
  40. data/lib/authproto/dpop/client.rb +28 -25
  41. data/lib/authproto/dpop/key_set.rb +2 -0
  42. data/lib/authproto/dpop/nonce_manager.rb +23 -20
  43. data/lib/authproto/dpop/proof_generator.rb +6 -3
  44. data/lib/authproto/dpop/stored_nonce.rb +7 -5
  45. data/lib/authproto/dpop.rb +2 -0
  46. data/lib/authproto/encryption.rb +2 -0
  47. data/lib/authproto/http_client.rb +5 -5
  48. data/lib/authproto/http_helpers.rb +6 -0
  49. data/lib/authproto/metadata/authorization_server.rb +4 -3
  50. data/lib/authproto/metadata/client_metadata.rb +6 -2
  51. data/lib/authproto/metadata/resource_server.rb +4 -3
  52. data/lib/authproto/minisky.rb +120 -33
  53. data/lib/authproto/par/client.rb +4 -2
  54. data/lib/authproto/par/client_assertion.rb +4 -1
  55. data/lib/authproto/par/request.rb +2 -0
  56. data/lib/authproto/par/response.rb +2 -0
  57. data/lib/authproto/par.rb +2 -0
  58. data/lib/authproto/pkce.rb +2 -0
  59. data/lib/authproto/serialization/session.rb +2 -2
  60. data/lib/authproto/serialization/stored_nonce.rb +2 -2
  61. data/lib/authproto/state/session.rb +8 -41
  62. data/lib/authproto/state/session_info.rb +150 -0
  63. data/lib/authproto/state/session_manager.rb +18 -15
  64. data/lib/authproto/state.rb +3 -1
  65. data/lib/authproto/storage/interface.rb +10 -0
  66. data/lib/authproto/storage/key_builder.rb +3 -3
  67. data/lib/authproto/storage/memory.rb +24 -18
  68. data/lib/authproto/storage/sqlite.rb +14 -0
  69. data/lib/authproto/token/refresh.rb +2 -2
  70. data/lib/authproto/token/response.rb +2 -0
  71. data/lib/authproto/token/revocation.rb +4 -2
  72. data/lib/authproto/version.rb +1 -1
  73. data/lib/authproto.rb +6 -3
  74. data/sig/authproto/client.rbs +33 -10
  75. data/sig/authproto/dpop/client.rbs +9 -3
  76. data/sig/authproto/dpop/nonce_manager.rbs +6 -6
  77. data/sig/authproto/dpop/proof_generator.rbs +4 -4
  78. data/sig/authproto/dpop/stored_nonce.rbs +2 -2
  79. data/sig/authproto/http_client.rbs +23 -6
  80. data/sig/authproto/http_helpers.rbs +1 -0
  81. data/sig/authproto/metadata/authorization_server.rbs +3 -3
  82. data/sig/authproto/metadata/client_metadata.rbs +1 -1
  83. data/sig/authproto/metadata/resource_server.rbs +2 -2
  84. data/sig/authproto/minisky.rbs +57 -0
  85. data/sig/authproto/state/session.rbs +12 -6
  86. data/sig/authproto/state/session_info.rbs +23 -0
  87. data/sig/authproto/state/session_manager.rbs +7 -2
  88. data/sig/authproto/storage/interface.rbs +1 -0
  89. data/sig/authproto/storage/key_builder.rbs +1 -1
  90. data/sig/authproto/storage/memory.rbs +1 -1
  91. data/sig/authproto/storage/sqlite.rbs +1 -0
  92. data/sig/authproto/token/revocation.rbs +1 -0
  93. data/sig/authproto.rbs +3 -8
  94. metadata +37 -15
  95. data/examples/confidential_client/Gemfile +0 -14
  96. data/examples/confidential_client/README.md +0 -236
  97. data/examples/confidential_client/app.rb +0 -308
  98. data/examples/confidential_client/public/styles.css +0 -70
  99. data/examples/confidential_client/scripts/generate_keys.rb +0 -21
  100. data/examples/confidential_client/views/authorized.erb +0 -46
  101. data/examples/confidential_client/views/index.erb +0 -44
  102. data/sig/authproto/minisky_oauth.rbs +0 -27
  103. /data/examples/{confidential_client/config/oauth-client-metadata.example.json → basic_webapp/config/oauth-client-metadata.production.json} +0 -0
  104. /data/examples/{confidential_client → basic_webapp}/config.ru +0 -0
  105. /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-1-sign-in.png +0 -0
  106. /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-2-success.png +0 -0
@@ -0,0 +1,59 @@
1
+ * { box-sizing: border-box; }
2
+ body { margin: 0; color: #172033; background: #fff; font: 16px/1.6 system-ui, sans-serif; }
3
+ h1 { margin: 0 0 0.5rem; line-height: 1.2; }
4
+ h1 a { color: #172033; text-decoration: none; }
5
+ p { margin: 0.5rem 0 1rem; }
6
+ a, .link-button { color: #176bc2; }
7
+ button, input { font: inherit; }
8
+ button { border: 0; border-radius: 0.5rem; padding: 0.6rem 1.4rem; background: #287fd1; color: white; cursor: pointer; }
9
+ input { min-width: 0; width: 100%; border: 1px solid #cbd1da; border-radius: 0.5rem; padding: 0.6rem; }
10
+ label { display: block; margin-bottom: 0.3rem; }
11
+ .login-page { display: flex; min-height: 100vh; align-items: center; }
12
+ .login-header { width: 45%; align-self: stretch; display: flex; flex-direction: column; justify-content: center;
13
+ align-items: flex-end; padding: 3rem; background: #f3f4f6; text-align: right; }
14
+ .login-header h1 { font-size: 3rem; }
15
+ .login-header p { max-width: 22rem; color: #667085; }
16
+ .login-form { width: 100%; max-width: 30rem; padding: 3rem; }
17
+ .login-form button { margin-top: 1.5rem; }
18
+ .handle-input { display: flex; align-items: center; gap: 0.5rem; }
19
+ .handle-input span { color: #667085; }
20
+ .bookmarks-page { max-width: 54rem; margin: 0 auto; padding: 3rem 1.5rem; }
21
+ .bookmarks-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
22
+ .bookmarks-header p { overflow-wrap: anywhere; font-size: 0.85rem; }
23
+ .muted, time { color: #667085; }
24
+ .search-form { margin: 2rem 0 1rem; }
25
+ .search-controls { display: flex; align-items: center; gap: 0.75rem; }
26
+ .fetch-form { margin: 1rem 0 2rem; }
27
+ .link-button { background: none; padding: 0; border-radius: 0; text-decoration: underline; }
28
+ .bookmark-list { margin: 0; padding: 0; list-style: none; }
29
+ .bookmark { padding: 1.5rem 0; border-bottom: 1px solid #e5e7eb; }
30
+ .bookmark header { display: flex; flex-wrap: wrap; column-gap: 1rem; align-items: baseline; }
31
+ .bookmark header a { font-size: 0.85rem; }
32
+ .post-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.75rem 0 0; }
33
+ .pagination { display: flex; justify-content: center; gap: 0.5rem; margin-top: 2rem; }
34
+ .pagination a, .pagination span { padding: 0.3rem 0.7rem; border-radius: 0.3rem; }
35
+ .pagination [aria-current] { color: white; background: #287fd1; }
36
+ .pagination [aria-disabled] { color: #929aa7; }
37
+ .message { padding: 1rem 1.5rem; overflow-wrap: anywhere; }
38
+ .message-error { background: #fef2f2; color: #b91c1c; }
39
+ .message-notice { background: #f0fdf4; color: #15803d; }
40
+ .empty-state { margin: 2rem 0; color: #667085; }
41
+
42
+ @media (max-width: 640px) {
43
+ .login-page { flex-direction: column; align-items: stretch; }
44
+ .login-header { width: 100%; align-items: flex-start; padding: 2rem; text-align: left; }
45
+ .login-header h1 { font-size: 2rem; }
46
+ .login-form { padding: 2rem; }
47
+ .search-controls { flex-wrap: wrap; }
48
+ .search-controls input { flex-basis: 100%; }
49
+ }
50
+
51
+ @media (prefers-color-scheme: dark) {
52
+ body { color: #e5e7eb; background: #111827; }
53
+ h1 a { color: #e5e7eb; }
54
+ .login-header { background: #1f2937; }
55
+ input { color: #e5e7eb; background: #1f2937; border-color: #4b5563; }
56
+ a, .link-button { color: #7cbcff; }
57
+ .muted, time, .login-header p, .empty-state { color: #a4adbb; }
58
+ .bookmark { border-color: #374151; }
59
+ }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'jose'
5
+ require 'json'
6
+
7
+ key = JOSE::JWK.generate_key([:ec, "P-256"])
8
+ key_id = "key-#{Time.now.to_i}"
9
+
10
+ private_jwk = key.to_map.to_h.merge("kid" => key_id, "use" => "sig")
11
+ public_jwk = key.to_public_map.to_h.merge("kid" => key_id, "use" => "sig")
12
+
13
+ puts "=" * 40
14
+ puts "PRIVATE KEY".center(40)
15
+ puts "=" * 40
16
+
17
+ puts
18
+ puts "Copy this JSON into config/keys.json. The key object should be passed as the `singing_key` to the " +
19
+ "`AuthProto::Client` initializer. It must NOT be accessible publicly."
20
+ puts
21
+
22
+ puts JSON.pretty_generate('keys' => [private_jwk])
23
+ puts
24
+
25
+ puts "=" * 40
26
+ puts "PUBLIC KEY".center(40)
27
+ puts "=" * 40
28
+
29
+ puts
30
+ puts "Copy this JSON into config/oauth-client-metadata.json. This is a public key read by the authorization " +
31
+ "server so that it can validate the client assertions generated by your app."
32
+ puts
33
+
34
+ puts JSON.pretty_generate('jwks' => { 'keys' => [public_jwk] })
35
+ puts
@@ -0,0 +1,86 @@
1
+ <main class="bookmarks-page">
2
+ <header class="bookmarks-header">
3
+ <div>
4
+ <h1><a href="/bookmarks">Your bookmarks</a></h1>
5
+ <p class="muted">
6
+ Signed in as <%= html_escape(session[:handle] ? "@#{session[:handle]}" : current_session.did) %>
7
+ </p>
8
+ </div>
9
+
10
+ <form method="post" action="/logout">
11
+ <input type="hidden" name="authenticity_token" value="<%= html_escape(csrf_token) %>">
12
+ <button type="submit" class="link-button">Sign out</button>
13
+ </form>
14
+ </header>
15
+
16
+ <form method="get" action="/bookmarks" class="search-form" role="search">
17
+ <label for="q">Search your bookmarks:</label>
18
+
19
+ <div class="search-controls">
20
+ <input id="q" name="q" type="search" placeholder="Text to find" value="<%= html_escape @query %>">
21
+ <button type="submit">Search</button>
22
+ <% unless @query.empty? %><a href="/bookmarks">Clear</a><% end %>
23
+ </div>
24
+ </form>
25
+
26
+ <% unless @fetched %>
27
+ <p>Your bookmarks haven't been fetched yet.</p>
28
+ <% end %>
29
+
30
+ <form method="post" action="/fetch" class="fetch-form">
31
+ <input type="hidden" name="authenticity_token" value="<%= html_escape(csrf_token) %>">
32
+ <button type="submit" class="link-button">
33
+ <%= @fetched ? 'Fetch bookmarks again' : 'Fetch your bookmarks' %>
34
+ </button>
35
+ </form>
36
+
37
+ <% unless @query.empty? %>
38
+ <p>Bookmarks containing “<%= html_escape @query %>”:</p>
39
+ <% end %>
40
+
41
+ <% if @bookmarks.empty? %>
42
+ <p class="empty-state"><%= @query.empty? ? 'No bookmarks saved yet.' : 'No matching bookmarks.' %></p>
43
+ <% end %>
44
+
45
+ <ol class="bookmark-list">
46
+ <% @bookmarks.each do |post| %>
47
+ <li>
48
+ <article class="bookmark">
49
+ <header>
50
+ <strong>@<%= html_escape(post.author_handle) %></strong>
51
+ <a href="<%= html_escape(post.post_url) %>">
52
+ <time datetime="<%= post.posted_at.utc.iso8601 %>">
53
+ <%= post.posted_at.utc.strftime('%-d %b %Y, %H:%M') %>
54
+ </time>
55
+ </a>
56
+ </header>
57
+ <p class="post-text"><%= html_escape(post.text) %></p>
58
+ </article>
59
+ </li>
60
+ <% end %>
61
+ </ol>
62
+
63
+ <% if @query.empty? && @total_pages > 1 %>
64
+ <nav class="pagination" aria-label="Bookmark pages">
65
+ <% if @page > 1 %>
66
+ <a href="/bookmarks?page=<%= @page - 1 %>" aria-label="Previous page">&lt;</a>
67
+ <% else %>
68
+ <span aria-disabled="true">&lt;</span>
69
+ <% end %>
70
+
71
+ <% @page_numbers.each do |number| %>
72
+ <% if number == @page %>
73
+ <span aria-current="page"><%= number %></span>
74
+ <% else %>
75
+ <a href="/bookmarks?page=<%= number %>"><%= number %></a>
76
+ <% end %>
77
+ <% end %>
78
+
79
+ <% if @page < @total_pages %>
80
+ <a href="/bookmarks?page=<%= @page + 1 %>" aria-label="Next page">&gt;</a>
81
+ <% else %>
82
+ <span aria-disabled="true">&gt;</span>
83
+ <% end %>
84
+ </nav>
85
+ <% end %>
86
+ </main>
@@ -0,0 +1,17 @@
1
+ <main class="login-page">
2
+ <header class="login-header">
3
+ <h1>Sign in</h1>
4
+ <p>Enter your AT Protocol handle to sync your private Bluesky bookmarks.</p>
5
+ </header>
6
+
7
+ <form method="post" action="/authenticate" class="login-form">
8
+ <input type="hidden" name="authenticity_token" value="<%= html_escape csrf_token %>">
9
+ <label for="handle">Handle</label>
10
+ <div class="handle-input">
11
+ <span aria-hidden="true">@</span>
12
+ <input id="handle" name="handle" type="text" placeholder="handle.bsky.social" required
13
+ autocapitalize="none" autocorrect="off" autocomplete="username" spellcheck="false">
14
+ </div>
15
+ <button type="submit">Next</button>
16
+ </form>
17
+ </main>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Bluesky Bookmarks</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="/styles.css">
8
+ </head>
9
+ <body>
10
+ <% if session[:error] %>
11
+ <div class="message message-error" role="alert"><%= html_escape session.delete(:error) %></div>
12
+ <% end %>
13
+
14
+ <% if session[:notice] %>
15
+ <div class="message message-notice" role="status"><%= html_escape session.delete(:notice) %></div>
16
+ <% end %>
17
+
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- authproto (0.3.0.beta3)
4
+ authproto (0.3.0.beta5)
5
5
  didkit (~> 0.5.0)
6
6
  jose (~> 1.2)
7
7
  jwt (~> 3.3)
@@ -91,7 +91,7 @@ DEPENDENCIES
91
91
  sqlite3
92
92
 
93
93
  CHECKSUMS
94
- authproto (0.3.0.beta3)
94
+ authproto (0.3.0.beta5)
95
95
  base58 (0.2.3) sha256=fda5c5d3bda8b429ad0d1a5309c2d1e488ba46f0a2ab99a639890f26c61bf3be
96
96
  base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
97
97
  bundler (4.0.23) sha256=407ba8a1d928f412847f819aa5f8b6aef7c59fb51feb517112af8a165487287b
@@ -1,6 +1,6 @@
1
- # Minisky OAuth Console Example
1
+ # Minisky OAuth console example
2
2
 
3
- This is an example showing how to do an (experimental) OAuth client based on Minisky from the `irb` level, both locally and against the client metadata hosted on a production server. Both configurations are *public* clients.
3
+ This is an example showing how to use an (experimental) OAuth client based on Minisky from the `irb` level, both locally and against the client metadata hosted on a production server. Both configurations are *public* clients.
4
4
 
5
5
  Note: both variants receive and save the access tokens locally on your machine, and in both you perform requests using the received token locally in `irb`. The production server code only serves the JSON file and prints the callback params, it does not use the `AuthProto` library itself.
6
6
 
@@ -8,13 +8,11 @@ Note: both variants receive and save the access tokens locally on your machine,
8
8
  ## Requirements
9
9
 
10
10
  - Ruby 3.3+
11
- - Bundler
12
- - A domain name for your application that matches your client metadata (required for production)
13
- - SSL certificate for your domain (required for production)
11
+ - a domain name and an SSL certificate for your application for live deployment
14
12
 
15
13
  ## Setup
16
14
 
17
- 1. Clone the repository and navigate to the example directory:
15
+ 1. Clone the repository and navigate to the example app directory:
18
16
 
19
17
  ```bash
20
18
  cd examples/minisky_console
@@ -26,7 +24,7 @@ cd examples/minisky_console
26
24
  bundle install
27
25
  ```
28
26
 
29
- 3. Generate an encryption key:
27
+ 3. Generate an encryption key for encrypting session data:
30
28
 
31
29
  ```bash
32
30
  openssl rand -base64 32
@@ -36,15 +34,20 @@ ATPROTO_MASTER_KEY=<value from above>
36
34
  ```
37
35
 
38
36
 
37
+ ## Configuration
38
+
39
+ This example is configured to only use an SQLite storage using a database in `db/localhost_auth.sqlite3` or `db/production_auth.sqlite3`. The client metadata is hardcoded in the `localhost.rb` script for localhost, and in the `app.rb` mini-server for production.
40
+
41
+
39
42
  ## Localhost use
40
43
 
41
- Run `bin/console`, then:
44
+ Run `bin/console` (or `bundle exec irb`) then:
42
45
 
43
46
  ```rb
44
47
  require_relative 'localhost'
45
48
 
46
- client = create_client('your.pds.hostname.here')
47
- authorize(client)
49
+ client = create_client
50
+ authorize(client, 'your.handle')
48
51
  ```
49
52
 
50
53
  This will print:
@@ -56,7 +59,7 @@ https://....
56
59
  Waiting for OAuth callback at http://127.0.0.1:9292/callback (Ctrl-C to cancel)
57
60
  ```
58
61
 
59
- Open this URL and authorize the app. The example starts a temporary inline HTTP server on the specified port on localhost, which only receives the callback and calls the provided block, which completes the authorization.
62
+ Open this URL and authorize the app. The example starts a temporary inline HTTP server on the specified port on localhost, which only receives the callback and calls the provided block, which completes the authorization. The script saves the session ID of the pending session in a local variable, and passes it back as `expected_session_id:` to the callback handling method in AuthProto for verification.
60
63
 
61
64
  Once the browser redirects to the callback URL after your approval, the console should print:
62
65
 
@@ -65,17 +68,23 @@ Authentication complete ✓
65
68
  Your session id: ......
66
69
  ```
67
70
 
68
- The callback block supplies `expected_session_id:` from the authorization result
69
- retained locally before opening the browser. The library checks it before exchanging the code.
71
+ Then, you can run `client.get_request(...)` and `client.post_request(...)` to perform authorized actions on the given account. By default, the example asks for permissions `repo:app.bsky.feed.post` and `rpc:app.bsky.feed.getTimeline?aud=*`, which allow calling `getTimeline` and creating/modifying posts. Try e.g.:
70
72
 
71
- Then, you can run `client.get_request(...)` and `client.post_request(...)` to perform authorized actions on the given account. By default, the example asks for permissions `repo:app.bsky.feed.post` and `rpc:app.bsky.feed.getTimeline?aud=*`, which allow calling `getTimeline` and creating/modifying posts.
73
+ ```rb
74
+ client.get_request('app.bsky.feed.getTimeline', { limit: 10 })
75
+ ```
72
76
 
73
- To restore a session after closing and reopening the console, write down the sesion ID printed after successful authentication, and then pass it back to the `OAuthClient` constructor:
77
+ To restore a session after closing and reopening the console, write down the sesion ID printed after successful authentication, and then pass it back to the `Minisky::OAuth` constructor:
74
78
 
75
79
  ```rb
76
- client = create_client('your.pds.hostname.here', session_id: '123456-789-abc-...')
80
+ client = create_client(session_id: '123456-789-abc-...')
77
81
  ```
78
82
 
83
+ The localhost script uses the `Minisky::OAuth.for_localhost` helper with the `REDIRECT_URI` and `SCOPE`
84
+ constants declared in `localhost.rb`. Keep those values unchanged when restoring a stored session, since they determine
85
+ the client ID, and a session may only be restored for the same client ID it was created for.
86
+
87
+
79
88
  ## Production use
80
89
 
81
90
  Deploy the code in `examples/minisky_console` to a production server using a method of your choice. The relevant part is in the `app.rb` file.
@@ -91,8 +100,8 @@ Locally, run `bin/console`, then:
91
100
  ```rb
92
101
  require_relative 'production'
93
102
 
94
- client = create_client('your.server.hostname', 'your.pds.hostname')
95
- authorize(client)
103
+ client = create_client('your.server.hostname')
104
+ authorize(client, 'your.handle')
96
105
  ```
97
106
 
98
107
  This will print:
@@ -110,11 +119,6 @@ Copy the printed command back to the console:
110
119
  handle_callback(client, { ... })
111
120
  ```
112
121
 
113
- Use the same local `client` that started this authorization attempt. The helper
114
- passes its remembered session ID as `expected_session_id:` and forwards only the
115
- `code`, `state`, and `iss` callback parameters. The expected ID is not supplied by
116
- the callback page. Each console client supports one current login attempt.
117
-
118
122
  This will print:
119
123
 
120
124
  ```
@@ -124,8 +128,8 @@ Your session id: ......
124
128
 
125
129
  Then, you can run `client.get_request(...)` and `client.post_request(...)` to perform authorized actions on the given account.
126
130
 
127
- Again, to restore a session after closing and reopening the console, write down the sesion ID printed after successful authentication, and then pass it back to the `OAuthClient` constructor:
131
+ Again, to restore a session after closing and reopening the console, write down the sesion ID printed after successful authentication, and then pass it back to the `Minisky::OAuth` constructor:
128
132
 
129
133
  ```rb
130
- client = create_client('your.server.hostname', 'your.pds.hostname', session_id: '123456-789-abc-...')
134
+ client = create_client('your.server.hostname', session_id: '123456-789-abc-...')
131
135
  ```
@@ -23,8 +23,8 @@ get "/" do
23
23
 
24
24
  "To start authentication, run this in bin/console:\n\n" +
25
25
  "require_relative 'production'\n" +
26
- "client = create_client('#{$server_host}', 'target.pds.hostname')\n" +
27
- "authorize(client)\n\n" +
26
+ "client = create_client('#{$server_host}')\n" +
27
+ "authorize(client, 'your.handle')\n\n" +
28
28
  "Then open the printed URL and authorize the app. You will receive a hash with data, which you need to paste to:\n\n" +
29
29
  "handle_callback(client, { ... })\n"
30
30
  end
@@ -43,7 +43,7 @@ get "/callback" do
43
43
  elsif params[:code] && params[:state] && params[:iss]
44
44
  "To complete authentication, run this in the console where you started the authentication flow " +
45
45
  "(replace \"client\" with the local variable name you've used):\n\n" +
46
- "handle_callback(client, #{params.slice(:code, :state, :iss).map { |k, v| [k.to_sym, v] }.to_h.inspect})\n"
46
+ "handle_callback(client, #{params.inspect})\n"
47
47
  else
48
48
  "Missing params"
49
49
  end
@@ -4,7 +4,6 @@ require 'authproto/insecure_http_client'
4
4
  require 'authproto/localhost_server'
5
5
  require 'authproto/minisky'
6
6
  require 'dotenv/load'
7
- require 'uri'
8
7
 
9
8
  AuthProto.configure do |config|
10
9
  config.http_client = AuthProto::InsecureHTTPClient.new(timeout: 10)
@@ -16,21 +15,20 @@ end
16
15
 
17
16
  REDIRECT_URI = 'http://127.0.0.1:9292/callback'
18
17
  SCOPE = 'atproto repo:app.bsky.feed.post rpc:app.bsky.feed.getTimeline?aud=*'
19
- CLIENT_ID = 'http://localhost/?' + URI.encode_www_form({ redirect_uri: REDIRECT_URI, scope: SCOPE })
20
18
 
21
- def create_client(pds, session_id: nil)
22
- Minisky::OAuthClient.new(pds, client_id: CLIENT_ID, redirect_uri: REDIRECT_URI, session_id: session_id)
19
+ def create_client(session_id: nil)
20
+ Minisky::OAuth.for_localhost(redirect_uri: REDIRECT_URI, scope: SCOPE, session_id: session_id)
23
21
  end
24
22
 
25
- def authorize(client)
26
- auth = client.authorize(pds: "https://#{client.host}", scope: SCOPE)
23
+ def authorize(client, handle)
24
+ auth = client.authorize(handle: handle, scope: SCOPE)
27
25
 
28
26
  puts "Open this URL in the browser and complete authorization:"
29
27
  puts auth[:url]
30
28
  puts
31
29
 
32
30
  AuthProto::LocalhostServer.start(client.oauth_client.client_metadata) do |json|
33
- client.handle_callback(**json, expected_session_id: auth.fetch(:session_id))
31
+ client.handle_callback(json, expected_session_id: auth.fetch(:session_id))
34
32
  end
35
33
 
36
34
  puts "Authentication complete ✓"
@@ -12,16 +12,16 @@ AuthProto.configure do |config|
12
12
  )
13
13
  end
14
14
 
15
- def create_client(server_hostname, pds, session_id: nil)
16
- Minisky::OAuthClient.new(pds,
15
+ def create_client(server_hostname, session_id: nil)
16
+ Minisky::OAuth.new(
17
17
  client_id: "https://#{server_hostname}/oauth-client-metadata.json",
18
18
  redirect_uri: "https://#{server_hostname}/callback",
19
19
  session_id: session_id
20
20
  )
21
21
  end
22
22
 
23
- def authorize(client)
24
- auth = client.authorize(pds: "https://#{client.host}", scope: client.oauth_client.client_metadata.scope)
23
+ def authorize(client, handle)
24
+ auth = client.authorize(handle: handle, scope: client.oauth_client.client_metadata.scope)
25
25
 
26
26
  puts "Open this URL in the browser and complete authorization:"
27
27
  puts auth[:url]
@@ -29,10 +29,8 @@ end
29
29
 
30
30
  def handle_callback(client, json)
31
31
  # Use the ID retained by this local client, not a value copied from the callback page.
32
- result = client.handle_callback(
33
- **json.slice(:code, :state, :iss), expected_session_id: client.session_id
34
- )
32
+ result = client.handle_callback(json, expected_session_id: client.session_id)
35
33
 
36
34
  puts "Authentication complete ✓"
37
- puts "Your session id: #{result[:session_id]}"
35
+ puts "Your session id: #{result.session_id}"
38
36
  end