authproto 0.3.0.beta3 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -1
- data/README.md +474 -311
- data/examples/basic_webapp/Gemfile +14 -0
- data/examples/{confidential_client → basic_webapp}/Gemfile.lock +1 -1
- data/examples/basic_webapp/README.md +300 -0
- data/examples/basic_webapp/app.rb +351 -0
- data/examples/basic_webapp/config/oauth-client-metadata.localhost.json +11 -0
- data/examples/basic_webapp/public/styles.css +346 -0
- data/examples/basic_webapp/scripts/generate_keys.rb +35 -0
- data/examples/basic_webapp/views/authorized.erb +48 -0
- data/examples/basic_webapp/views/index.erb +48 -0
- data/examples/{confidential_client → basic_webapp}/views/layout.erb +2 -2
- data/examples/bookmarks/Gemfile +16 -0
- data/examples/bookmarks/Gemfile.lock +158 -0
- data/examples/bookmarks/README.md +170 -0
- data/examples/bookmarks/Rakefile +23 -0
- data/examples/bookmarks/app/account.rb +16 -0
- data/examples/bookmarks/app/bookmark.rb +89 -0
- data/examples/bookmarks/app/init.rb +26 -0
- data/examples/bookmarks/app/oauth.rb +43 -0
- data/examples/bookmarks/app/server.rb +184 -0
- data/examples/bookmarks/config/oauth-client-metadata.localhost.json +11 -0
- data/examples/bookmarks/config/oauth-client-metadata.production.json +19 -0
- data/examples/bookmarks/config.ru +5 -0
- data/examples/bookmarks/db/migrate/20261107004141_create_bookmarks.rb +27 -0
- data/examples/bookmarks/db/schema.rb +33 -0
- data/examples/bookmarks/public/styles.css +59 -0
- data/examples/bookmarks/scripts/generate_keys.rb +35 -0
- data/examples/bookmarks/views/bookmarks.erb +86 -0
- data/examples/bookmarks/views/index.erb +17 -0
- data/examples/bookmarks/views/layout.erb +20 -0
- data/examples/minisky_console/Gemfile.lock +2 -2
- data/examples/minisky_console/README.md +29 -25
- data/examples/minisky_console/app.rb +3 -3
- data/examples/minisky_console/localhost.rb +5 -7
- data/examples/minisky_console/production.rb +6 -8
- data/lib/authproto/client.rb +505 -151
- data/lib/authproto/configuration.rb +1 -1
- data/lib/authproto/dpop/client.rb +28 -25
- data/lib/authproto/dpop/key_set.rb +2 -0
- data/lib/authproto/dpop/nonce_manager.rb +24 -25
- data/lib/authproto/dpop/proof_generator.rb +9 -5
- data/lib/authproto/dpop/stored_nonce.rb +7 -5
- data/lib/authproto/dpop.rb +2 -0
- data/lib/authproto/encryption.rb +31 -12
- data/lib/authproto/http_client.rb +13 -12
- data/lib/authproto/http_helpers.rb +6 -0
- data/lib/authproto/metadata/authorization_server.rb +15 -3
- data/lib/authproto/metadata/client_metadata.rb +34 -3
- data/lib/authproto/metadata/resource_server.rb +7 -6
- data/lib/authproto/minisky.rb +120 -33
- data/lib/authproto/par/client.rb +4 -2
- data/lib/authproto/par/client_assertion.rb +4 -1
- data/lib/authproto/par/request.rb +2 -0
- data/lib/authproto/par/response.rb +2 -0
- data/lib/authproto/par.rb +2 -0
- data/lib/authproto/pkce.rb +2 -0
- data/lib/authproto/serialization/session.rb +4 -2
- data/lib/authproto/serialization/stored_nonce.rb +2 -2
- data/lib/authproto/serialization/token_set.rb +5 -2
- data/lib/authproto/state/session.rb +23 -20
- data/lib/authproto/state/session_info.rb +150 -0
- data/lib/authproto/state/session_manager.rb +46 -19
- data/lib/authproto/state/token_set.rb +6 -3
- data/lib/authproto/state.rb +4 -2
- data/lib/authproto/storage/interface.rb +10 -0
- data/lib/authproto/storage/key_builder.rb +3 -3
- data/lib/authproto/storage/memory.rb +24 -18
- data/lib/authproto/storage/sqlite.rb +14 -0
- data/lib/authproto/token/identity.rb +54 -0
- data/lib/authproto/token/refresh.rb +44 -54
- data/lib/authproto/token/response.rb +75 -0
- data/lib/authproto/token/revocation.rb +94 -0
- data/lib/authproto/version.rb +1 -1
- data/lib/authproto.rb +6 -3
- data/sig/authproto/client.rbs +38 -13
- data/sig/authproto/dpop/client.rbs +9 -3
- data/sig/authproto/dpop/nonce_manager.rbs +6 -6
- data/sig/authproto/dpop/proof_generator.rbs +4 -4
- data/sig/authproto/dpop/stored_nonce.rbs +2 -2
- data/sig/authproto/encryption.rbs +4 -2
- data/sig/authproto/http_client.rbs +23 -7
- data/sig/authproto/http_helpers.rbs +1 -0
- data/sig/authproto/metadata/authorization_server.rbs +3 -3
- data/sig/authproto/metadata/client_metadata.rbs +2 -1
- data/sig/authproto/metadata/resource_server.rbs +2 -2
- data/sig/authproto/minisky.rbs +57 -0
- data/sig/authproto/state/session.rbs +13 -4
- data/sig/authproto/state/session_info.rbs +23 -0
- data/sig/authproto/state/session_manager.rbs +10 -3
- data/sig/authproto/storage/interface.rbs +1 -0
- data/sig/authproto/storage/key_builder.rbs +1 -1
- data/sig/authproto/storage/memory.rbs +1 -1
- data/sig/authproto/storage/sqlite.rbs +1 -0
- data/sig/authproto/token/refresh.rbs +2 -1
- data/sig/authproto/token/response.rbs +12 -0
- data/sig/authproto/token/revocation.rbs +15 -0
- data/sig/authproto.rbs +3 -8
- metadata +53 -19
- data/examples/confidential_client/Gemfile +0 -14
- data/examples/confidential_client/README.md +0 -236
- data/examples/confidential_client/app.rb +0 -291
- data/examples/confidential_client/public/styles.css +0 -70
- data/examples/confidential_client/scripts/generate_keys.rb +0 -21
- data/examples/confidential_client/views/authorized.erb +0 -46
- data/examples/confidential_client/views/index.erb +0 -44
- data/sig/authproto/minisky_oauth.rbs +0 -27
- /data/examples/{confidential_client/config/oauth-client-metadata.example.json → basic_webapp/config/oauth-client-metadata.production.json} +0 -0
- /data/examples/{confidential_client → basic_webapp}/config.ru +0 -0
- /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-1-sign-in.png +0 -0
- /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-2-success.png +0 -0
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'cgi'
|
|
4
|
-
require 'json'
|
|
5
|
-
require 'securerandom'
|
|
6
|
-
require 'time'
|
|
7
|
-
require 'uri'
|
|
8
|
-
|
|
9
|
-
require 'authproto'
|
|
10
|
-
require 'dotenv/load'
|
|
11
|
-
require 'faraday'
|
|
12
|
-
require 'sinatra/base'
|
|
13
|
-
require 'sinatra/reloader'
|
|
14
|
-
|
|
15
|
-
session_secret = ENV.fetch("SESSION_SECRET") { SecureRandom.hex(32) }
|
|
16
|
-
raise "SESSION_SECRET must be at least 64 characters long (got: #{session_secret})" unless session_secret.length >= 64
|
|
17
|
-
|
|
18
|
-
# Main app entry point
|
|
19
|
-
class ExampleApp < Sinatra::Base
|
|
20
|
-
def check_stored_session(session_id)
|
|
21
|
-
return false unless session_id
|
|
22
|
-
|
|
23
|
-
settings.oauth_client.authorized?(session_id)
|
|
24
|
-
rescue AuthProto::SessionError
|
|
25
|
-
false
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
configure :development do
|
|
29
|
-
register Sinatra::Reloader
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Initialize the AT Protocol OAuth client
|
|
33
|
-
configure do
|
|
34
|
-
# Configure AuthProto settings
|
|
35
|
-
AuthProto.configure do |config|
|
|
36
|
-
config.http_client = AuthProto::HTTPClient.new(timeout: 10, verify_ssl: true)
|
|
37
|
-
config.dpop_nonce_lifetime = 300
|
|
38
|
-
|
|
39
|
-
case ENV.fetch("STORAGE_BACKEND", "memory")
|
|
40
|
-
when "memory"
|
|
41
|
-
config.storage = AuthProto::Storage::Memory.new
|
|
42
|
-
when "sqlite"
|
|
43
|
-
config.storage = AuthProto::Storage::SQLite.new(
|
|
44
|
-
path: ENV.fetch("SQLITE_PATH", File.join(__dir__, "db", "authproto.sqlite3"))
|
|
45
|
-
)
|
|
46
|
-
when "redis"
|
|
47
|
-
config.storage = AuthProto::Storage::Redis.new(
|
|
48
|
-
redis_client: Redis.new(url: ENV.fetch("REDIS_URL"))
|
|
49
|
-
)
|
|
50
|
-
else
|
|
51
|
-
raise "STORAGE_BACKEND must be memory, sqlite, or redis"
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Load client metadata
|
|
56
|
-
metadata_path = File.join(__dir__, "config", "oauth-client-metadata.json")
|
|
57
|
-
metadata = JSON.parse(File.read(metadata_path))
|
|
58
|
-
|
|
59
|
-
client_id = metadata['client_id']
|
|
60
|
-
|
|
61
|
-
if client_id.chomp("/") == "http://localhost"
|
|
62
|
-
scope = CGI.escape(metadata['scope'])
|
|
63
|
-
redirect_uri = CGI.escape(metadata['redirect_uris'][0])
|
|
64
|
-
client_id += "?scope=#{scope}&redirect_uri=#{redirect_uri}"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Private client-authentication keys are kept outside public metadata.
|
|
68
|
-
signing_key = JSON.parse(File.read(File.join(__dir__, "config", "keys.json")))["keys"].first
|
|
69
|
-
|
|
70
|
-
# Create OAuth client
|
|
71
|
-
set :oauth_client, AuthProto::Client.new(
|
|
72
|
-
client_id: client_id,
|
|
73
|
-
redirect_uri: metadata['redirect_uris'][0],
|
|
74
|
-
metadata: metadata,
|
|
75
|
-
signing_key: signing_key
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
set :host_authorization, {
|
|
80
|
-
permitted_hosts: ["localhost", ENV.fetch("PERMITTED_DOMAIN", nil)].compact
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
use Rack::Session::Cookie,
|
|
84
|
-
key: "atproto.session",
|
|
85
|
-
expire_after: 86_400, # 1 day in seconds
|
|
86
|
-
secret: session_secret,
|
|
87
|
-
secure: ENV.fetch("RACK_ENV", "development") == "production", # Only send over HTTPS
|
|
88
|
-
httponly: true, # Not accessible via JavaScript
|
|
89
|
-
same_site: :lax # CSRF protection
|
|
90
|
-
|
|
91
|
-
helpers do
|
|
92
|
-
def recover_session
|
|
93
|
-
session_id = session[:oauth_session_id]
|
|
94
|
-
return nil unless session_id
|
|
95
|
-
|
|
96
|
-
begin
|
|
97
|
-
# Check if session is still valid
|
|
98
|
-
return nil unless settings.oauth_client.authorized?(session_id)
|
|
99
|
-
|
|
100
|
-
session_id
|
|
101
|
-
rescue AuthProto::Client::SessionError
|
|
102
|
-
# Clear invalid session
|
|
103
|
-
session.delete(:oauth_session_id)
|
|
104
|
-
nil
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
get "/" do
|
|
110
|
-
# Check for existing session
|
|
111
|
-
redirect "/authorized" if recover_session
|
|
112
|
-
|
|
113
|
-
erb :index
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
get "/oauth-client-metadata.json" do
|
|
117
|
-
content_type :json
|
|
118
|
-
|
|
119
|
-
# Read metadata from config file
|
|
120
|
-
metadata_path = File.join(__dir__, "config", "oauth-client-metadata.json")
|
|
121
|
-
metadata = JSON.parse(File.read(metadata_path))
|
|
122
|
-
|
|
123
|
-
# This file contains only the public counterparts of config/keys.json.
|
|
124
|
-
JSON.generate(metadata)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Start OAuth flow
|
|
128
|
-
post "/auth" do
|
|
129
|
-
handle = params[:handle]
|
|
130
|
-
|
|
131
|
-
begin
|
|
132
|
-
# Start authorization flow
|
|
133
|
-
auth = settings.oauth_client.authorize(
|
|
134
|
-
handle: handle,
|
|
135
|
-
scope: "atproto repo:app.bsky.feed.post"
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
# Bind the pending authorization attempt to this browser, separately from any active login.
|
|
139
|
-
session[:pending_oauth_session_id] = auth[:session_id]
|
|
140
|
-
|
|
141
|
-
# Redirect to authorization URL
|
|
142
|
-
redirect auth[:url]
|
|
143
|
-
rescue StandardError => e
|
|
144
|
-
session[:error] = "Authorization failed: #{e.message}"
|
|
145
|
-
redirect "/"
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# OAuth callback handler
|
|
150
|
-
get "/callback" do
|
|
151
|
-
# Handle the callback
|
|
152
|
-
result = settings.oauth_client.handle_callback(
|
|
153
|
-
code: params[:code],
|
|
154
|
-
state: params[:state],
|
|
155
|
-
iss: params[:iss],
|
|
156
|
-
expected_session_id: session[:pending_oauth_session_id]
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
session.delete(:pending_oauth_session_id)
|
|
160
|
-
|
|
161
|
-
# Remember the authenticated session ID.
|
|
162
|
-
session[:oauth_session_id] = result[:session_id]
|
|
163
|
-
|
|
164
|
-
redirect "/authorized"
|
|
165
|
-
rescue StandardError => e
|
|
166
|
-
session[:error] = "Callback failed: #{e.message}"
|
|
167
|
-
redirect "/"
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
# Show authorized state and test API call
|
|
171
|
-
get "/authorized" do
|
|
172
|
-
session_id = session[:oauth_session_id]
|
|
173
|
-
return redirect "/" unless check_stored_session(session_id)
|
|
174
|
-
|
|
175
|
-
begin
|
|
176
|
-
# Get current session tokens
|
|
177
|
-
oauth_session = settings.oauth_client.get_tokens(session_id)
|
|
178
|
-
|
|
179
|
-
# Check if token needs refresh
|
|
180
|
-
if oauth_session[:expires_in] < 30
|
|
181
|
-
# Refresh token
|
|
182
|
-
oauth_session = settings.oauth_client.refresh_token(session_id)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
# Make test API call to com.atproto.identity.resolveHandle
|
|
186
|
-
conn = Faraday.new(url: "https://api.bsky.app") do |f|
|
|
187
|
-
f.request :json
|
|
188
|
-
f.response :json
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# Get auth headers for request
|
|
192
|
-
headers = settings.oauth_client.auth_headers(
|
|
193
|
-
session_id: session_id,
|
|
194
|
-
method: 'GET',
|
|
195
|
-
url: "https://api.bsky.app/xrpc/com.atproto.identity.resolveHandle"
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
# Make authenticated request
|
|
199
|
-
response = conn.get("/xrpc/com.atproto.identity.resolveHandle") do |req|
|
|
200
|
-
headers.each { |k, v| req.headers[k] = v }
|
|
201
|
-
req.params[:handle] = "bsky.app"
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
@api_result = response.body
|
|
205
|
-
@session = oauth_session
|
|
206
|
-
erb :authorized
|
|
207
|
-
rescue StandardError => e
|
|
208
|
-
session[:error] = "API call failed: #{e.message}"
|
|
209
|
-
redirect "/"
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
post "/posts" do
|
|
214
|
-
session_id = session[:oauth_session_id]
|
|
215
|
-
return redirect "/" unless check_stored_session(session_id)
|
|
216
|
-
|
|
217
|
-
text = params[:text].to_s
|
|
218
|
-
if text.strip.empty?
|
|
219
|
-
session[:error] = "Post text cannot be empty"
|
|
220
|
-
return redirect "/authorized"
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
if text.length > 300 || text.bytesize > 3_000
|
|
224
|
-
session[:error] = "Post text must be at most 300 characters and 3,000 bytes"
|
|
225
|
-
return redirect "/authorized"
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
oauth_session = settings.oauth_client.session_manager.get_session(session_id)
|
|
229
|
-
|
|
230
|
-
pds_url = ENV['PDS_URL'] || DIDKit::DID.new(oauth_session.did).document.pds_endpoint
|
|
231
|
-
raise "No HTTPS PDS location found" unless pds_url && URI(pds_url).is_a?(URI::HTTPS)
|
|
232
|
-
|
|
233
|
-
endpoint = URI.join(
|
|
234
|
-
"#{pds_url.chomp("/")}/",
|
|
235
|
-
"xrpc/com.atproto.repo.createRecord"
|
|
236
|
-
).to_s
|
|
237
|
-
|
|
238
|
-
headers = settings.oauth_client.auth_headers(
|
|
239
|
-
session_id: session_id,
|
|
240
|
-
method: 'POST',
|
|
241
|
-
url: endpoint
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
conn = Faraday.new do |f|
|
|
245
|
-
f.request :json
|
|
246
|
-
f.response :json
|
|
247
|
-
end
|
|
248
|
-
response = conn.post(endpoint) do |req|
|
|
249
|
-
headers.each { |key, value| req.headers[key] = value }
|
|
250
|
-
req.body = {
|
|
251
|
-
repo: oauth_session.did,
|
|
252
|
-
collection: "app.bsky.feed.post",
|
|
253
|
-
record: {
|
|
254
|
-
"$type": "app.bsky.feed.post",
|
|
255
|
-
text: text,
|
|
256
|
-
langs: ["en"],
|
|
257
|
-
createdAt: Time.now.utc.iso8601(3)
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
unless response.success?
|
|
263
|
-
error_body = response.body.is_a?(String) ? response.body : JSON.generate(response.body)
|
|
264
|
-
raise "PDS rejected post (#{response.status}): #{error_body}"
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
session[:notice] = "Post published successfully"
|
|
268
|
-
redirect "/authorized"
|
|
269
|
-
rescue StandardError => e
|
|
270
|
-
session[:error] = "Publishing post failed: #{e.message}"
|
|
271
|
-
redirect "/authorized"
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
get "/signout" do
|
|
275
|
-
if session[:oauth_session_id]
|
|
276
|
-
# Clean up stored session
|
|
277
|
-
settings.oauth_client.delete_session(session[:oauth_session_id])
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
session.clear
|
|
281
|
-
session[:notice] = "Successfully signed out"
|
|
282
|
-
redirect "/"
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
# Helper method to check if user is authenticated
|
|
286
|
-
def authenticated?
|
|
287
|
-
return false unless session[:tokens]
|
|
288
|
-
|
|
289
|
-
settings.oauth_client.authorized?(session[:tokens][:session_id])
|
|
290
|
-
end
|
|
291
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
max-width: 800px;
|
|
3
|
-
margin: 0 auto;
|
|
4
|
-
padding: 20px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.header {
|
|
8
|
-
max-width: 400px;
|
|
9
|
-
margin: 0 auto;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.error {
|
|
13
|
-
background-color: #ffebee;
|
|
14
|
-
color: #c62828;
|
|
15
|
-
padding: 10px;
|
|
16
|
-
margin-bottom: 20px;
|
|
17
|
-
border-radius: 4px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.auth-form {
|
|
21
|
-
max-width: 400px;
|
|
22
|
-
margin: 40px auto;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.form-group {
|
|
26
|
-
margin-bottom: 15px;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.form-group label {
|
|
30
|
-
display: block;
|
|
31
|
-
margin-bottom: 5px;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.form-group input {
|
|
35
|
-
width: 100%;
|
|
36
|
-
padding: 8px;
|
|
37
|
-
border: 1px solid #ddd;
|
|
38
|
-
border-radius: 4px;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
button {
|
|
42
|
-
background: #2196f3;
|
|
43
|
-
color: white;
|
|
44
|
-
padding: 10px 20px;
|
|
45
|
-
border: none;
|
|
46
|
-
border-radius: 4px;
|
|
47
|
-
cursor: pointer;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
button:hover {
|
|
51
|
-
background: #1976d2;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.token-info,
|
|
55
|
-
.api-test {
|
|
56
|
-
margin-top: 20px;
|
|
57
|
-
padding: 15px;
|
|
58
|
-
background: #f5f5f5;
|
|
59
|
-
border-radius: 4px;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
pre {
|
|
63
|
-
overflow-x: auto;
|
|
64
|
-
white-space: pre-wrap;
|
|
65
|
-
word-wrap: break-word;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
code {
|
|
69
|
-
font-size: 14px;
|
|
70
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'jose'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
key = JOSE::JWK.generate_key([:ec, "P-256"])
|
|
7
|
-
|
|
8
|
-
private_jwk = key.to_map.to_h.merge("kid" => "key-1", "use" => "sig")
|
|
9
|
-
public_jwk = key.to_public_map.to_h.merge("kid" => "key-1", "use" => "sig")
|
|
10
|
-
|
|
11
|
-
config_dir = File.expand_path('../config', __dir__)
|
|
12
|
-
private_path = File.join(config_dir, 'keys.json')
|
|
13
|
-
|
|
14
|
-
File.open(private_path, File::WRONLY | File::CREAT | File::TRUNC, 0o600) do |file|
|
|
15
|
-
file.chmod(0o600)
|
|
16
|
-
file.write(JSON.pretty_generate('keys' => [private_jwk]) + "\n")
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
File.write(File.join(config_dir, 'public-keys.json'), JSON.pretty_generate('keys' => [public_jwk]) + "\n")
|
|
20
|
-
|
|
21
|
-
puts "Private keys saved to config/keys.json; publish only config/public-keys.json in metadata."
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
<div class="flex flex-col items-center md:flex md:flex-row md:justify-stretch md:items-center min-h-screen min-w-screen bg-white text-gray-900 dark:bg-gray-900 dark:text-gray-100">
|
|
2
|
-
<div class="px-6 pt-4 md:max-w-lg md:grid md:content-center md:justify-items-end md:self-stretch md:w-1/2 md:max-w-fix md:p-4 md:text-right md:dark:border-r md:dark:border-gray-700 md:bg-gray-100 md:dark:bg-gray-800">
|
|
3
|
-
<h1 class="text-xl md:text-2xl lg:text-5xl md:mt-4 mb-4 font-semibold text-brand">Successfully Authenticated!</h1>
|
|
4
|
-
</div>
|
|
5
|
-
<div class="w-full px-6 md:max-w-3xl md:px-12">
|
|
6
|
-
<div class="space-y-8">
|
|
7
|
-
<% if session[:error] %>
|
|
8
|
-
<div class="mb-8 bg-red-50 border-red-700 text-red-700 p-4 rounded-md">
|
|
9
|
-
<%= session[:error] %>
|
|
10
|
-
<% session[:error] = nil %>
|
|
11
|
-
</div>
|
|
12
|
-
<% end %>
|
|
13
|
-
|
|
14
|
-
<% if session[:notice] %>
|
|
15
|
-
<div class="mb-8 bg-green-50 border-green-700 text-green-700 p-4 rounded-md">
|
|
16
|
-
<%= session[:notice] %>
|
|
17
|
-
<% session[:notice] = nil %>
|
|
18
|
-
</div>
|
|
19
|
-
<% end %>
|
|
20
|
-
|
|
21
|
-
<form method="post" action="/posts" class="flex flex-col py-4 space-y-4">
|
|
22
|
-
<fieldset>
|
|
23
|
-
<label for="post-text" class="mb-1 block text-gray-600 dark:text-gray-400 text-sm font-medium">New Bluesky post</label>
|
|
24
|
-
<textarea id="post-text" name="text" rows="4" maxlength="300" required placeholder="What's up?" class="w-full rounded-lg text-gray-700 dark:text-gray-100 bg-gray-100 dark:bg-gray-800 p-3 outline-none border-solid border-2 border-transparent hover:border-gray-400 focus:border-brand dark:hover:border-gray-500"></textarea>
|
|
25
|
-
</fieldset>
|
|
26
|
-
<div>
|
|
27
|
-
<button type="submit" class="py-2 px-6 rounded-lg cursor-pointer touch-manipulation tracking-wide bg-blue-400 text-white">Post to Bluesky</button>
|
|
28
|
-
</div>
|
|
29
|
-
</form>
|
|
30
|
-
|
|
31
|
-
<div class="token-info">
|
|
32
|
-
<p class="mb-1 text-gray-600 dark:text-gray-400 text-sm font-medium">Token Information</p>
|
|
33
|
-
<pre class="rounded-lg text-gray-700 dark:text-gray-100 bg-gray-100 dark:bg-slate-800 border border-gray-400 p-2 overflow-auto"><code><%= JSON.pretty_generate(@session) %></code></pre>
|
|
34
|
-
</div>
|
|
35
|
-
|
|
36
|
-
<div class="api-test">
|
|
37
|
-
<p class="mb-1 text-gray-600 dark:text-gray-400 text-sm font-medium">Test API Call Result</p>
|
|
38
|
-
<pre class="rounded-lg text-gray-700 dark:text-gray-100 bg-gray-100 dark:bg-slate-800 border border-gray-400 p-2 overflow-auto"><code><%= JSON.pretty_generate(@api_result) %></code></pre>
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<div class="flex">
|
|
42
|
-
<a href="/signout" aria-label="Signout" class="py-2 px-6 rounded-lg truncate cursor-pointer touch-manipulation tracking-wide overflow-hidden bg-blue-400 text-white">Sign out</a>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<div class="flex flex-col items-center md:flex md:flex-row md:justify-stretch md:items-center min-h-screen min-w-screen bg-white text-gray-900 dark:bg-gray-900 dark:text-gray-100">
|
|
2
|
-
<div class="px-6 pt-4 md:max-w-lg md:grid md:content-center md:justify-items-end md:self-stretch md:w-1/2 md:max-w-fix md:p-4 md:text-right md:dark:border-r md:dark:border-gray-700 md:bg-gray-100 md:dark:bg-gray-800">
|
|
3
|
-
<h1 class="text-xl md:text-2xl lg:text-5xl md:mt-4 mb-4 font-semibold text-brand">Sign in</h1>
|
|
4
|
-
<p class="hidden md:block max-w-xs text-gray-500 dark:text-gray-500">Enter your AT Protocol handle</p>
|
|
5
|
-
</div>
|
|
6
|
-
<div class="w-full px-6 md:max-w-3xl md:px-12">
|
|
7
|
-
<form method="post" action="/auth" class="flex flex-col py-4 space-y-4">
|
|
8
|
-
<div class="space-y-4">
|
|
9
|
-
<% if session[:error] %>
|
|
10
|
-
<div class="mb-8 bg-red-50 border-red-700 text-red-700 p-4 rounded-md">
|
|
11
|
-
<%= session[:error] %>
|
|
12
|
-
<% session[:error] = nil %>
|
|
13
|
-
</div>
|
|
14
|
-
<% end %>
|
|
15
|
-
<% if session[:notice] %>
|
|
16
|
-
<div class="mb-8 bg-yellow-50 border-yellow-700 text-yellow-700 p-4 rounded-md">
|
|
17
|
-
<%= session[:notice] %>
|
|
18
|
-
<% session[:notice] = nil %>
|
|
19
|
-
</div>
|
|
20
|
-
<% end %>
|
|
21
|
-
<fieldset>
|
|
22
|
-
<p class="mb-1 text-gray-600 dark:text-gray-400 text-sm font-medium">Handle</p>
|
|
23
|
-
<div class="flex flex-col space-y-4">
|
|
24
|
-
<div class="pl-1 pr-2 min-h-12 flex items-center justify-stretch rounded-lg text-gray-700 dark:text-gray-100 bg-gray-100 has-[:focus]:bg-gray-200 dark:bg-gray-800 dark:has-[:focus]:bg-gray-700 outline-none border-solid border-2 border-transparent hover:border-gray-400 has-[:focus]:border-brand hover:has-[:focus]:border-brand dark:hover:border-gray-500">
|
|
25
|
-
<div class="self-start shrink-0 grow-0 w-8 h-12 flex items-center justify-center text-gray-500">
|
|
26
|
-
<div>
|
|
27
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-5">
|
|
28
|
-
<path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M12 4a8 8 0 1 0 4.21 14.804 1 1 0 0 1 1.054 1.7A9.958 9.958 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 1.104-.27 2.31-.949 3.243-.716.984-1.849 1.6-3.331 1.465a4.207 4.207 0 0 1-2.93-1.585c-.94 1.21-2.388 1.94-3.985 1.715-2.53-.356-4.04-2.91-3.682-5.458.358-2.547 2.514-4.586 5.044-4.23.905.127 1.68.536 2.286 1.126a1 1 0 0 1 1.964.368l-.515 3.545v.002a2.222 2.222 0 0 0 1.999 2.526c.75.068 1.212-.21 1.533-.65.358-.493.566-1.245.566-2.067a8 8 0 0 0-8-8Zm-.112 5.13c-1.195-.168-2.544.819-2.784 2.529-.24 1.71.784 3.03 1.98 3.198 1.195.168 2.543-.819 2.784-2.529.24-1.71-.784-3.03-1.98-3.198Z"></path>
|
|
29
|
-
</svg>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
<div class="relative">
|
|
33
|
-
<input class="w-full bg-transparent bg-clip-padding text-base text-inherit outline-none dark:placeholder-gray-500" name="handle" type="text" placeholder="handle.bsky.social" aria-label="Handle" autocapitalize="none" autocorrect="off" autocomplete="username" spellcheck="false" dir="auto" enterkeyhint="next" required title="valid handle">
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
</fieldset>
|
|
38
|
-
</div>
|
|
39
|
-
<div class="pt-4">
|
|
40
|
-
<button role="Button" type="submit" aria-label="Next" class="py-2 px-6 rounded-lg truncate cursor-pointer touch-manipulation tracking-wide overflow-hidden bg-blue-400 text-white">Next</button>
|
|
41
|
-
</div>
|
|
42
|
-
</form>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Signatures for the methods defined by the optional Minisky adapter.
|
|
2
|
-
# Additional methods mixed in from Minisky::Requests belong to the minisky gem.
|
|
3
|
-
class Minisky
|
|
4
|
-
class OAuthClient
|
|
5
|
-
include AuthProto::HTTPHelpers
|
|
6
|
-
MAX_NONCE_RETRIES: Integer
|
|
7
|
-
attr_reader host: String
|
|
8
|
-
attr_reader oauth_client: AuthProto::Client
|
|
9
|
-
attr_reader session_id: String?
|
|
10
|
-
|
|
11
|
-
def initialize: (String host, client_id: String, redirect_uri: String, ?metadata: AuthProto::json_object?, ?signing_key: (AuthProto::json_object | JOSE::JWK)?, ?session_id: String?) -> void
|
|
12
|
-
def config: () -> nil
|
|
13
|
-
def authorize: (?handle: String?, ?pds: String?, ?scope: String) -> AuthProto::authorization_result
|
|
14
|
-
def handle_callback: (
|
|
15
|
-
code: String, state: String, iss: String, expected_session_id: String
|
|
16
|
-
) -> AuthProto::callback_result
|
|
17
|
-
def get_request: (String | URI::HTTP method, ?Hash[untyped, untyped]? params, ?auth: bool, ?headers: Hash[String, String]?) -> untyped
|
|
18
|
-
def post_request: (String | URI::HTTP method, ?untyped data, ?auth: bool, ?headers: Hash[String, String]?, ?params: Hash[untyped, untyped]?) -> untyped
|
|
19
|
-
def log_in: (*untyped args) -> bot
|
|
20
|
-
def perform_token_refresh: () -> AuthProto::refreshed_tokens
|
|
21
|
-
def check_access: () -> (:ok | :refreshed)
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
def oauth_request: (singleton(Net::HTTP::Get) | singleton(Net::HTTP::Post) request_class, URI::HTTP url, Hash[String, String] headers, ?body: String?) -> Net::HTTPResponse
|
|
25
|
-
def authentication_error: (Net::HTTPResponse response) -> String?
|
|
26
|
-
end
|
|
27
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|