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
|
@@ -0,0 +1,57 @@
|
|
|
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 OAuth
|
|
5
|
+
include AuthProto::HTTPHelpers
|
|
6
|
+
MAX_NONCE_RETRIES: Integer
|
|
7
|
+
def host: () -> String
|
|
8
|
+
def did: () -> String
|
|
9
|
+
attr_reader oauth_client: AuthProto::Client
|
|
10
|
+
attr_reader session_id: String?
|
|
11
|
+
|
|
12
|
+
def self.for_localhost: (
|
|
13
|
+
redirect_uri: (String | URI::Generic), ?scope: String, ?session_id: String?
|
|
14
|
+
) -> instance
|
|
15
|
+
|
|
16
|
+
def self.with_oauth_client: (AuthProto::Client oauth_client, ?session_id: String?) -> instance
|
|
17
|
+
|
|
18
|
+
def initialize: (
|
|
19
|
+
client_id: String,
|
|
20
|
+
redirect_uri: (String | URI::HTTPS),
|
|
21
|
+
?metadata: AuthProto::json_object?,
|
|
22
|
+
?signing_key: (AuthProto::json_object | JOSE::JWK)?,
|
|
23
|
+
?session_id: String?,
|
|
24
|
+
?oauth_client: AuthProto::Client?
|
|
25
|
+
) -> void
|
|
26
|
+
def config: () -> nil
|
|
27
|
+
def authorize: (?handle: String?, ?pds: (String | URI::HTTPS)?, ?scope: String) -> AuthProto::authorization_result
|
|
28
|
+
def handle_callback: (
|
|
29
|
+
Hash[String | Symbol, untyped] callback_params, expected_session_id: String
|
|
30
|
+
) -> AuthProto::State::SessionInfo
|
|
31
|
+
def get_request: (
|
|
32
|
+
String | URI::HTTP method,
|
|
33
|
+
?Hash[untyped, untyped]? params,
|
|
34
|
+
?auth: bool,
|
|
35
|
+
?headers: Hash[String, String]?
|
|
36
|
+
) -> untyped
|
|
37
|
+
def post_request: (
|
|
38
|
+
String | URI::HTTP method,
|
|
39
|
+
?untyped data,
|
|
40
|
+
?auth: bool,
|
|
41
|
+
?headers: Hash[String, String]?,
|
|
42
|
+
?params: Hash[untyped, untyped]?
|
|
43
|
+
) -> untyped
|
|
44
|
+
def log_in: (*untyped args) -> bot
|
|
45
|
+
def perform_token_refresh: () -> AuthProto::State::SessionInfo
|
|
46
|
+
def check_access: () -> (:ok | :refreshed)
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
def oauth_request: (
|
|
50
|
+
singleton(Net::HTTP::Get) | singleton(Net::HTTP::Post) request_class,
|
|
51
|
+
URI::HTTP url,
|
|
52
|
+
Hash[String, String] headers,
|
|
53
|
+
?body: String?
|
|
54
|
+
) -> Net::HTTPResponse
|
|
55
|
+
def authentication_error: (Net::HTTPResponse response) -> String?
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -10,22 +10,31 @@ module AuthProto
|
|
|
10
10
|
attr_reader dpop_key: DPoP::KeySet
|
|
11
11
|
attr_reader signing_key_id: String?
|
|
12
12
|
attr_reader signing_key_thumbprint: String?
|
|
13
|
-
attr_reader
|
|
13
|
+
attr_reader requested_scope: String
|
|
14
14
|
attr_reader pkce_verifier: String
|
|
15
15
|
attr_reader pkce_challenge: String
|
|
16
16
|
attr_reader auth_server: Metadata::AuthorizationServer?
|
|
17
17
|
attr_reader did: String?
|
|
18
18
|
attr_reader tokens: TokenSet?
|
|
19
19
|
|
|
20
|
-
def initialize: (
|
|
20
|
+
def initialize: (
|
|
21
|
+
client_id: String,
|
|
22
|
+
scope: String,
|
|
23
|
+
?auth_server: Metadata::AuthorizationServer?,
|
|
24
|
+
?did: String?,
|
|
25
|
+
?signing_key_id: String?,
|
|
26
|
+
?signing_key_thumbprint: String?,
|
|
27
|
+
?dpop_key: DPoP::KeySet,
|
|
28
|
+
?authorization_expires_at: Time?
|
|
29
|
+
) -> void
|
|
21
30
|
def clear_state_token: () -> nil
|
|
22
31
|
def authorization_server=: (Metadata::AuthorizationServer server) -> Metadata::AuthorizationServer
|
|
23
32
|
def did=: (String did) -> String
|
|
24
33
|
def tokens=: (TokenSet tokens) -> String
|
|
25
|
-
def session_data: () -> AuthProto::
|
|
34
|
+
def session_data: () -> AuthProto::State::SessionInfo
|
|
26
35
|
def pending?: () -> bool
|
|
36
|
+
def can_be_revoked?: () -> bool
|
|
27
37
|
def tokens_valid?: () -> bool
|
|
28
|
-
alias authorized? tokens_valid?
|
|
29
38
|
def renewable?: () -> bool
|
|
30
39
|
end
|
|
31
40
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module AuthProto
|
|
2
|
+
module State
|
|
3
|
+
class SessionInfo
|
|
4
|
+
def initialize: (Session session) -> void
|
|
5
|
+
def session_id: () -> String
|
|
6
|
+
def access_token: () -> String?
|
|
7
|
+
def refresh_token: () -> String?
|
|
8
|
+
def expires_at: () -> Time?
|
|
9
|
+
def expires_in: () -> Integer?
|
|
10
|
+
def requested_scope: () -> String
|
|
11
|
+
def granted_scope: () -> String?
|
|
12
|
+
def did: () -> String?
|
|
13
|
+
def pds: () -> String?
|
|
14
|
+
def to_h: () -> Hash[Symbol, String | Integer | Time | nil]
|
|
15
|
+
def pending?: () -> bool
|
|
16
|
+
def tokens_valid?: () -> bool
|
|
17
|
+
alias authorized? tokens_valid?
|
|
18
|
+
def renewable?: () -> bool
|
|
19
|
+
def has_limited_scope?: () -> bool
|
|
20
|
+
def can_be_revoked?: () -> bool
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -2,18 +2,25 @@ module AuthProto
|
|
|
2
2
|
module State
|
|
3
3
|
class SessionManager
|
|
4
4
|
@serializer: Serialization::Session
|
|
5
|
+
@client_id: String
|
|
5
6
|
@supported_signing_keys: Hash[String, String]
|
|
6
7
|
|
|
7
|
-
def initialize: (?supported_signing_keys: Hash[String, String]) -> void
|
|
8
|
-
def create_session: (
|
|
8
|
+
def initialize: (client_id: String, ?supported_signing_keys: Hash[String, String]) -> void
|
|
9
|
+
def create_session: (
|
|
10
|
+
client_id: String,
|
|
11
|
+
scope: String,
|
|
12
|
+
?auth_server: Metadata::AuthorizationServer?,
|
|
13
|
+
?did: String?,
|
|
14
|
+
?signing_key_id: String?
|
|
15
|
+
) -> Session
|
|
9
16
|
def update_session: (Session session) -> Session
|
|
10
17
|
def complete_authorization: (Session session) -> Session
|
|
11
18
|
def get_session: (String session_id) -> Session?
|
|
12
19
|
def get_session_by_state_token: (String? state) -> Session?
|
|
13
20
|
def delete_session: (String session_id) -> void
|
|
14
|
-
def cleanup_expired: () -> void
|
|
15
21
|
|
|
16
22
|
private
|
|
23
|
+
def validate_client_id: (String client_id) -> void
|
|
17
24
|
def session_ttl: (Session session) -> Integer?
|
|
18
25
|
end
|
|
19
26
|
end
|
|
@@ -10,6 +10,7 @@ module AuthProto
|
|
|
10
10
|
def get: (String key) -> untyped
|
|
11
11
|
def delete: (String key) -> bool
|
|
12
12
|
def exists?: (String key) -> bool
|
|
13
|
+
def cleanup_expired_records: () -> void
|
|
13
14
|
def with_lock: [T] (String key, ?ttl: Integer) { () -> T } -> T
|
|
14
15
|
|
|
15
16
|
# Protected in Ruby; RBS exposes protected methods as public.
|
|
@@ -5,7 +5,7 @@ module AuthProto
|
|
|
5
5
|
NAMESPACE_PREFIX: String
|
|
6
6
|
def self.session_key: (String id) -> String
|
|
7
7
|
def self.state_key: (String token) -> String
|
|
8
|
-
def self.nonce_key: (String session_id, String
|
|
8
|
+
def self.nonce_key: (String session_id, String origin) -> String
|
|
9
9
|
def self.lock_key: (String namespace, String id) -> String
|
|
10
10
|
|
|
11
11
|
private
|
|
@@ -6,6 +6,7 @@ module AuthProto
|
|
|
6
6
|
def get: (String key) -> untyped
|
|
7
7
|
def delete: (String key) -> true
|
|
8
8
|
def exists?: (String key) -> bool
|
|
9
|
+
def cleanup_expired_records: () -> void
|
|
9
10
|
def with_lock: [T] (String key, ?ttl: Integer) { () -> T } -> T
|
|
10
11
|
def clear: () -> void
|
|
11
12
|
|
|
@@ -15,7 +16,6 @@ module AuthProto
|
|
|
15
16
|
def expired?: (String key) -> bool
|
|
16
17
|
def lock_expired?: (String lock_key) -> bool
|
|
17
18
|
def set_expiration: (String key, Integer ttl) -> Integer
|
|
18
|
-
def cleanup_expired: () -> void
|
|
19
19
|
def start_cleanup_thread: () -> Thread
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -11,6 +11,7 @@ module AuthProto
|
|
|
11
11
|
def get: (String key) -> (String | Numeric | nil)
|
|
12
12
|
def delete: (String key) -> bool
|
|
13
13
|
def exists?: (String key) -> bool
|
|
14
|
+
def cleanup_expired_records: () -> void
|
|
14
15
|
def with_lock: [T] (String key, ?ttl: Integer) { () -> T } -> T
|
|
15
16
|
def close: () -> void
|
|
16
17
|
|
|
@@ -31,6 +31,7 @@ module AuthProto
|
|
|
31
31
|
def perform_refresh: () -> State::TokenSet
|
|
32
32
|
|
|
33
33
|
private
|
|
34
|
+
def revoke_rejected_refresh_token: (String token) -> void
|
|
34
35
|
def with_retries: [T] () { () -> T } -> T
|
|
35
36
|
def calculate_delay: () -> Float
|
|
36
37
|
def request_token_refresh: () -> State::TokenSet
|
|
@@ -40,7 +41,7 @@ module AuthProto
|
|
|
40
41
|
def process_successful_response: (http_response response) -> State::TokenSet
|
|
41
42
|
def handle_error_response: (http_response response) -> bot
|
|
42
43
|
def handle_rate_limit_response: (http_response response) -> bot
|
|
43
|
-
def
|
|
44
|
+
def validate_refresh_identity: (State::TokenSet tokens) -> void
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module AuthProto
|
|
2
|
+
module Token
|
|
3
|
+
class Revocation
|
|
4
|
+
include HTTPHelpers
|
|
5
|
+
class Error < AuthProto::Error
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def initialize: (session: State::Session, dpop_client: DPoP::Client, client_metadata: Metadata::ClientMetadata, ?client_assertion: PAR::ClientAssertion?) -> void
|
|
9
|
+
def revoke_token: (String token, token_type: String | Symbol) -> void
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
def make_request: (String token, String endpoint, String token_type) -> http_response
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/sig/authproto.rbs
CHANGED
|
@@ -6,18 +6,13 @@ end
|
|
|
6
6
|
module AuthProto
|
|
7
7
|
type json_object = Hash[String, untyped]
|
|
8
8
|
type http_body = String | Hash[untyped, untyped] | nil
|
|
9
|
-
type http_response = { status: Integer, headers: Hash[String, String], body: String? }
|
|
10
|
-
type session_data = { access_token: String, token_type: String, expires_in: Integer,
|
|
11
|
-
refresh_token: String?, scope: String, session_id: String, did: String }
|
|
12
|
-
type token_info = session_data
|
|
13
|
-
type refreshed_tokens = session_data
|
|
14
|
-
type callback_result = session_data
|
|
9
|
+
type http_response = { status: Integer | String, headers: Hash[String, String | Array[String]], body: String? }
|
|
15
10
|
type authorization_result = { url: String, session_id: String }
|
|
16
11
|
|
|
17
12
|
class Error < StandardError
|
|
18
13
|
end
|
|
19
14
|
|
|
20
|
-
class OAuthError < Error
|
|
15
|
+
class OAuthError < AuthProto::Error
|
|
21
16
|
attr_reader error_code: String
|
|
22
17
|
def initialize: (String message, String error_code) -> void
|
|
23
18
|
end
|
|
@@ -30,7 +25,7 @@ module AuthProto
|
|
|
30
25
|
def initialize: (String message) -> void
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
class ConfigurationError < Error
|
|
28
|
+
class ConfigurationError < AuthProto::Error
|
|
34
29
|
end
|
|
35
30
|
|
|
36
31
|
class Configuration
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: authproto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.0.
|
|
4
|
+
version: 0.3.0.beta5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Josh Huckabee
|
|
@@ -52,9 +52,16 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: 0.5.0
|
|
55
|
-
description: A Ruby
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
description: "\n A Ruby gem implementing an OAuth 2.1 client specifically targeted
|
|
56
|
+
for use in AT Protocol context. Supports both\n public and confidential clients,
|
|
57
|
+
handles DPoP, nonce management, client and server metadata JSON, PAR, PKCE,\n client
|
|
58
|
+
assertions for confidential clients, storage of session state, and at rest encryption
|
|
59
|
+
of stored tokens.\n Includes SQLite, Redis and in-memory storage backends, and
|
|
60
|
+
an adapter for using the Minisky gem with OAuth\n login support.\n\n This
|
|
61
|
+
gem deliberately does not support any features, profiles and configurations of OAuth
|
|
62
|
+
that are not currently\n used in ATProto, and does not support turning off any
|
|
63
|
+
additional requirements and restrictions that ATProto\n introduces on top of
|
|
64
|
+
standard OAuth specifications.\n "
|
|
58
65
|
email:
|
|
59
66
|
- jakub.suder@gmail.com
|
|
60
67
|
executables: []
|
|
@@ -65,19 +72,39 @@ files:
|
|
|
65
72
|
- MIT-LICENSE.txt
|
|
66
73
|
- README.md
|
|
67
74
|
- SECURITY.md
|
|
68
|
-
- examples/
|
|
69
|
-
- examples/
|
|
70
|
-
- examples/
|
|
71
|
-
- examples/
|
|
72
|
-
- examples/
|
|
73
|
-
- examples/
|
|
74
|
-
- examples/
|
|
75
|
-
- examples/
|
|
76
|
-
- examples/
|
|
77
|
-
- examples/
|
|
78
|
-
- examples/
|
|
79
|
-
- examples/
|
|
80
|
-
- examples/
|
|
75
|
+
- examples/basic_webapp/Gemfile
|
|
76
|
+
- examples/basic_webapp/Gemfile.lock
|
|
77
|
+
- examples/basic_webapp/README.md
|
|
78
|
+
- examples/basic_webapp/app.rb
|
|
79
|
+
- examples/basic_webapp/config.ru
|
|
80
|
+
- examples/basic_webapp/config/oauth-client-metadata.localhost.json
|
|
81
|
+
- examples/basic_webapp/config/oauth-client-metadata.production.json
|
|
82
|
+
- examples/basic_webapp/public/styles.css
|
|
83
|
+
- examples/basic_webapp/screenshots/screenshot-1-sign-in.png
|
|
84
|
+
- examples/basic_webapp/screenshots/screenshot-2-success.png
|
|
85
|
+
- examples/basic_webapp/scripts/generate_keys.rb
|
|
86
|
+
- examples/basic_webapp/views/authorized.erb
|
|
87
|
+
- examples/basic_webapp/views/index.erb
|
|
88
|
+
- examples/basic_webapp/views/layout.erb
|
|
89
|
+
- examples/bookmarks/Gemfile
|
|
90
|
+
- examples/bookmarks/Gemfile.lock
|
|
91
|
+
- examples/bookmarks/README.md
|
|
92
|
+
- examples/bookmarks/Rakefile
|
|
93
|
+
- examples/bookmarks/app/account.rb
|
|
94
|
+
- examples/bookmarks/app/bookmark.rb
|
|
95
|
+
- examples/bookmarks/app/init.rb
|
|
96
|
+
- examples/bookmarks/app/oauth.rb
|
|
97
|
+
- examples/bookmarks/app/server.rb
|
|
98
|
+
- examples/bookmarks/config.ru
|
|
99
|
+
- examples/bookmarks/config/oauth-client-metadata.localhost.json
|
|
100
|
+
- examples/bookmarks/config/oauth-client-metadata.production.json
|
|
101
|
+
- examples/bookmarks/db/migrate/20261107004141_create_bookmarks.rb
|
|
102
|
+
- examples/bookmarks/db/schema.rb
|
|
103
|
+
- examples/bookmarks/public/styles.css
|
|
104
|
+
- examples/bookmarks/scripts/generate_keys.rb
|
|
105
|
+
- examples/bookmarks/views/bookmarks.erb
|
|
106
|
+
- examples/bookmarks/views/index.erb
|
|
107
|
+
- examples/bookmarks/views/layout.erb
|
|
81
108
|
- examples/minisky_console/Gemfile
|
|
82
109
|
- examples/minisky_console/Gemfile.lock
|
|
83
110
|
- examples/minisky_console/README.md
|
|
@@ -118,6 +145,7 @@ files:
|
|
|
118
145
|
- lib/authproto/serialization/token_set.rb
|
|
119
146
|
- lib/authproto/state.rb
|
|
120
147
|
- lib/authproto/state/session.rb
|
|
148
|
+
- lib/authproto/state/session_info.rb
|
|
121
149
|
- lib/authproto/state/session_manager.rb
|
|
122
150
|
- lib/authproto/state/token_set.rb
|
|
123
151
|
- lib/authproto/storage/interface.rb
|
|
@@ -125,7 +153,10 @@ files:
|
|
|
125
153
|
- lib/authproto/storage/memory.rb
|
|
126
154
|
- lib/authproto/storage/redis.rb
|
|
127
155
|
- lib/authproto/storage/sqlite.rb
|
|
156
|
+
- lib/authproto/token/identity.rb
|
|
128
157
|
- lib/authproto/token/refresh.rb
|
|
158
|
+
- lib/authproto/token/response.rb
|
|
159
|
+
- lib/authproto/token/revocation.rb
|
|
129
160
|
- lib/authproto/validated_uri.rb
|
|
130
161
|
- lib/authproto/version.rb
|
|
131
162
|
- sig/authproto.rbs
|
|
@@ -145,7 +176,7 @@ files:
|
|
|
145
176
|
- sig/authproto/metadata/authorization_server.rbs
|
|
146
177
|
- sig/authproto/metadata/client_metadata.rbs
|
|
147
178
|
- sig/authproto/metadata/resource_server.rbs
|
|
148
|
-
- sig/authproto/
|
|
179
|
+
- sig/authproto/minisky.rbs
|
|
149
180
|
- sig/authproto/par.rbs
|
|
150
181
|
- sig/authproto/par/client.rbs
|
|
151
182
|
- sig/authproto/par/client_assertion.rbs
|
|
@@ -158,6 +189,7 @@ files:
|
|
|
158
189
|
- sig/authproto/serialization/token_set.rbs
|
|
159
190
|
- sig/authproto/state.rbs
|
|
160
191
|
- sig/authproto/state/session.rbs
|
|
192
|
+
- sig/authproto/state/session_info.rbs
|
|
161
193
|
- sig/authproto/state/session_manager.rbs
|
|
162
194
|
- sig/authproto/state/token_set.rbs
|
|
163
195
|
- sig/authproto/storage/interface.rbs
|
|
@@ -167,6 +199,8 @@ files:
|
|
|
167
199
|
- sig/authproto/storage/redis_client.rbs
|
|
168
200
|
- sig/authproto/storage/sqlite.rbs
|
|
169
201
|
- sig/authproto/token/refresh.rbs
|
|
202
|
+
- sig/authproto/token/response.rbs
|
|
203
|
+
- sig/authproto/token/revocation.rbs
|
|
170
204
|
- sig/authproto/validated_uri.rbs
|
|
171
205
|
- sig/authproto/version.rbs
|
|
172
206
|
homepage: https://tangled.org/mackuba.eu/authproto
|
|
@@ -193,5 +227,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
193
227
|
requirements: []
|
|
194
228
|
rubygems_version: 4.0.23
|
|
195
229
|
specification_version: 4
|
|
196
|
-
summary: Ruby implementation of
|
|
230
|
+
summary: Ruby implementation of an AT Protocol specific OAuth client
|
|
197
231
|
test_files: []
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "authproto", path: "../.."
|
|
6
|
-
gem "dotenv"
|
|
7
|
-
gem "faraday"
|
|
8
|
-
gem "json"
|
|
9
|
-
gem "puma"
|
|
10
|
-
gem "rackup"
|
|
11
|
-
gem "redis"
|
|
12
|
-
gem "sinatra"
|
|
13
|
-
gem "sinatra-contrib"
|
|
14
|
-
gem "sqlite3", "~> 2.9"
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
# AT Protocol OAuth Confidential Client Example
|
|
2
|
-
|
|
3
|
-
This is an example implementation of a confidential OAuth client for the AT Protocol using the AuthProto gem. It demonstrates how to implement the OAuth flow for a web application, including DPoP token binding and secure session management.
|
|
4
|
-
|
|
5
|
-
<img src="https://github.com/mackuba/authproto/blob/main/examples/confidential_client/screenshots/screenshot-1-sign-in.png?raw=true" alt="Sign In Form Screenshot" title="Sign In Form" width="500">
|
|
6
|
-
|
|
7
|
-
<img src="https://github.com/mackuba/authproto/blob/main/examples/confidential_client/screenshots/screenshot-2-success.png?raw=true" alt="Sign In Success Screenshot" title="Sign In Success" width="500">
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
The example implements a simple web application using Sinatra that:
|
|
12
|
-
|
|
13
|
-
- Allows users to sign in with their AT Protocol handle (@handle) and make a test Bluesky post
|
|
14
|
-
- Implements the complete OAuth authorization flow
|
|
15
|
-
- Uses DPoP-bound tokens for API requests
|
|
16
|
-
- Demonstrates secure session management with encryption
|
|
17
|
-
- Shows how to make authenticated API calls to Bluesky
|
|
18
|
-
- Provides examples of both development and production storage configurations
|
|
19
|
-
- Supports running on localhost
|
|
20
|
-
|
|
21
|
-
## Requirements
|
|
22
|
-
|
|
23
|
-
- Ruby 3.3+
|
|
24
|
-
- Bundler
|
|
25
|
-
- A domain name for your application that matches your client metadata (required for production)
|
|
26
|
-
- SSL certificate for your domain (required for production)
|
|
27
|
-
- optionally, Redis for production
|
|
28
|
-
|
|
29
|
-
## Setup
|
|
30
|
-
|
|
31
|
-
1. Clone the repository and navigate to the example directory:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
cd examples/confidential_client
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
2. Install dependencies:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
bundle install
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
3. Generate EC keys for client authentication:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
bundle exec ruby scripts/generate_keys.rb
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
4. Generate session & encryption keys:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
openssl rand -base64 32
|
|
53
|
-
openssl rand -hex 32
|
|
54
|
-
|
|
55
|
-
cat > .env
|
|
56
|
-
ATPROTO_MASTER_KEY=<base64 value from first command>
|
|
57
|
-
SESSION_SECRET=<hex value from second command>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
5. Configure your client metadata:
|
|
61
|
-
- Copy the example metadata file over:
|
|
62
|
-
```
|
|
63
|
-
cp config/client-metadata.example.json config/oauth-client-metadata.json
|
|
64
|
-
```
|
|
65
|
-
- Set the correct `client_id` URL where your metadata will be hosted
|
|
66
|
-
- Configure valid `redirect_uris` for your application
|
|
67
|
-
- Copy the public JWKS from `config/public-keys.json` (not `config/keys.json`, which is the private keys) into the `jwks` field in oauth-client-metadata.json.
|
|
68
|
-
- For localhost testing, set `client_id` to `http://localhost/` and `redirect_uris` to `["http://127.0.0.1:9292/callback"]`
|
|
69
|
-
|
|
70
|
-
6. Set up environment variables:
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
# Your application's domain name
|
|
74
|
-
export PERMITTED_DOMAIN=your.domain.com
|
|
75
|
-
# or 127.0.0.1 for localhost testing
|
|
76
|
-
|
|
77
|
-
# Select a storage backend: memory (default), sqlite, or redis
|
|
78
|
-
export STORAGE_BACKEND=sqlite
|
|
79
|
-
|
|
80
|
-
# Optional SQLite path (defaults to ./db/authproto.sqlite3)
|
|
81
|
-
export SQLITE_PATH=/var/lib/my-app/authproto.sqlite3
|
|
82
|
-
|
|
83
|
-
# Required when STORAGE_BACKEND=redis
|
|
84
|
-
export REDIS_URL=redis://localhost:6379
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Configuration
|
|
88
|
-
|
|
89
|
-
### Storage Configuration
|
|
90
|
-
|
|
91
|
-
The example app supports in-memory, SQLite and Redis storage backends. Select
|
|
92
|
-
one by passing `STORAGE_BACKEND=memory`, `STORAGE_BACKEND=sqlite`, or
|
|
93
|
-
`STORAGE_BACKEND=redis`.
|
|
94
|
-
|
|
95
|
-
#### In-memory storage (for development)
|
|
96
|
-
|
|
97
|
-
```ruby
|
|
98
|
-
# config/development.rb
|
|
99
|
-
AuthProto.configure do |config|
|
|
100
|
-
config.storage = AuthProto::Storage::Memory.new
|
|
101
|
-
config.logger = Logger.new($stdout)
|
|
102
|
-
end
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
#### SQLite storage
|
|
106
|
-
|
|
107
|
-
SQLite can be used for persistent storage in development or in low traffic production setups:
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
export STORAGE_BACKEND=sqlite
|
|
111
|
-
export SQLITE_PATH=/var/lib/my-app/authproto.sqlite3
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### Redis storage
|
|
115
|
-
|
|
116
|
-
Use Redis in more complex production setups:
|
|
117
|
-
|
|
118
|
-
```ruby
|
|
119
|
-
# config/production.rb
|
|
120
|
-
require 'redis'
|
|
121
|
-
|
|
122
|
-
AuthProto.configure do |config|
|
|
123
|
-
redis_client = Redis.new(
|
|
124
|
-
url: ENV.fetch('REDIS_URL'),
|
|
125
|
-
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
config.storage = AuthProto::Storage::Redis.new(
|
|
129
|
-
redis_client: redis_client
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
config.logger = Logger.new($stdout)
|
|
133
|
-
end
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Host Authorization
|
|
137
|
-
|
|
138
|
-
This application requires specific domain configuration to function properly:
|
|
139
|
-
|
|
140
|
-
1. **Domain-Client Matching**: The domain where you run the application must exactly match the `client_id` domain in your client metadata. For example, if your `client_id` is `https://myapp.example.com/oauth-client-metadata.json`, the application must be accessible at `myapp.example.com`.
|
|
141
|
-
|
|
142
|
-
2. **Internet Accessibility**: The application must be accessible from the internet for AT Protocol OAuth to work. The Authorization Server needs to be able to reach your application's redirect URI during the OAuth flow.
|
|
143
|
-
|
|
144
|
-
3. **Quick Setup with Tailscale Funnel**: One easy way to expose your local development server to the internet is using Tailscale Funnel:
|
|
145
|
-
|
|
146
|
-
1. Set up [Tailscale Funnel](https://tailscale.com/kb/1223/funnel)
|
|
147
|
-
2. Ensure you have HTTPS certificates configured
|
|
148
|
-
5. Start your Funnel:
|
|
149
|
-
```bash
|
|
150
|
-
tailscale funnel 9292
|
|
151
|
-
```
|
|
152
|
-
4. Ensure your client_id and redirect_uris match your funnel path
|
|
153
|
-
5. Set the `PERMITTED_DOMAIN` environment variable to your Tailscale domain
|
|
154
|
-
```bash
|
|
155
|
-
export PERMITTED_DOMAIN=machinename.xyz.ts.net
|
|
156
|
-
```
|
|
157
|
-
6. Run the application (see below)
|
|
158
|
-
|
|
159
|
-
Your application will now be accessible via your Tailscale domain with HTTPS enabled.
|
|
160
|
-
|
|
161
|
-
### Session Security
|
|
162
|
-
|
|
163
|
-
The application uses encrypted sessions to store authorization data. Configure the session secret with:
|
|
164
|
-
|
|
165
|
-
```bash
|
|
166
|
-
export SESSION_SECRET=your-secure-random-string
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
If not set, a random secret will be generated on startup (not recommended for production).
|
|
170
|
-
|
|
171
|
-
The app stores the ID returned by `authorize` as `session[:pending_oauth_session_id]`
|
|
172
|
-
before redirecting. On callback, it passes that browser-session value as the required
|
|
173
|
-
`expected_session_id:` argument to `handle_callback`. The library rejects a missing
|
|
174
|
-
or mismatched ID before exchanging the code. After success, the app removes the
|
|
175
|
-
pending association and remembers the authenticated session separately.
|
|
176
|
-
|
|
177
|
-
The expected ID must come from the initiating browser session, never from the
|
|
178
|
-
callback URL or by looking up the returned `state`. This example supports one pending
|
|
179
|
-
login per browser; starting another replaces the previous pending association.
|
|
180
|
-
|
|
181
|
-
## Running the Application
|
|
182
|
-
|
|
183
|
-
### Development
|
|
184
|
-
```bash
|
|
185
|
-
RACK_ENV=development bundle exec rackup
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### Production
|
|
189
|
-
```bash
|
|
190
|
-
RACK_ENV=production bundle exec rackup -E production
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
This will start the server on `http://localhost:9292`.
|
|
194
|
-
|
|
195
|
-
## Troubleshooting
|
|
196
|
-
|
|
197
|
-
### Common Issues
|
|
198
|
-
|
|
199
|
-
1. "Invalid redirect URI":
|
|
200
|
-
- Ensure your redirect URI matches exactly what's in your client metadata
|
|
201
|
-
- Check that your domain matches the client_id domain
|
|
202
|
-
|
|
203
|
-
2. "Invalid client metadata":
|
|
204
|
-
- Verify your client metadata is accessible at the URL specified in client_id
|
|
205
|
-
- Check that your JSON is valid and contains all required fields
|
|
206
|
-
|
|
207
|
-
3. "Authorization failed":
|
|
208
|
-
- Verify your JWKS configuration
|
|
209
|
-
- Check that your DPoP proofs are being generated correctly
|
|
210
|
-
- Ensure your client authentication is working
|
|
211
|
-
|
|
212
|
-
4. "Storage errors":
|
|
213
|
-
- For SQLite storage, verify the database path is writable
|
|
214
|
-
- For Redis storage, verify Redis connection settings
|
|
215
|
-
- Check Redis SSL configuration if using encrypted connections
|
|
216
|
-
- Ensure proper Redis authentication credentials if required
|
|
217
|
-
|
|
218
|
-
5. "Session state lost":
|
|
219
|
-
- Verify storage configuration is correct
|
|
220
|
-
- Check that SQLite storage is on persistent local disk
|
|
221
|
-
- Check Redis connection stability if using Redis storage
|
|
222
|
-
- Ensure session TTLs are appropriately configured
|
|
223
|
-
|
|
224
|
-
## Understanding the Code
|
|
225
|
-
|
|
226
|
-
The example demonstrates several important concepts:
|
|
227
|
-
|
|
228
|
-
1. **Secure Storage**: The app shows proper configuration of in-memory, SQLite and Redis storage.
|
|
229
|
-
|
|
230
|
-
2. **Token Management**: All tokens are stored securely with encryption in the configured storage backend.
|
|
231
|
-
|
|
232
|
-
3. **Session Handling**: The app demonstrates proper session state management with atomic operations and locking.
|
|
233
|
-
|
|
234
|
-
4. **Error Recovery**: Includes examples of handling storage failures and token refresh scenarios.
|
|
235
|
-
|
|
236
|
-
The code is thoroughly commented to explain these concepts and their implementation details.
|