shakha 0.1.0

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.
data/lib/shakha.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shakha/version"
4
+ require "shakha/config"
5
+ require "shakha/engine"
6
+
7
+ module Shakha
8
+ class << self
9
+ def setup
10
+ yield(config)
11
+ end
12
+
13
+ def config
14
+ @config ||= Config.new
15
+ end
16
+
17
+ def verify_token(id_token, audience: nil)
18
+ JwtHandler.verify(id_token, audience: audience || default_audience)
19
+ end
20
+
21
+ def sign_token(payload, exp: 24.hours.from_now)
22
+ JwtHandler.encode(payload, exp: exp)
23
+ end
24
+
25
+ def derive_pairwise_sub(google_sub, client_id = nil)
26
+ Pairwise.derive(google_sub, client_id || default_client_id)
27
+ end
28
+
29
+ private
30
+
31
+ def default_audience
32
+ "origin:#{config.app_origin&.then { |url| URI.parse(url).origin }}"
33
+ end
34
+
35
+ def default_client_id
36
+ "origin:#{URI.parse(config.app_origin).origin}"
37
+ end
38
+ end
39
+
40
+ class ConfigurationError < StandardError; end
41
+ class JWTError < StandardError; end
42
+ class PKCEError < StandardError; end
43
+ class GoogleOAuthError < StandardError; end
44
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shakha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Asrat
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: jwt
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.7'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.7'
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.1'
40
+ description: |
41
+ Shakha handles Google OAuth + PKCE and gives your app a domain-scoped identity (pairwise_sub)
42
+ and a signed id_token. No client signup. No unnecessary scopes. Just identity.
43
+ email:
44
+ - asrat@example.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.txt
50
+ - README.md
51
+ - app/assets/stylesheets/shakha.css
52
+ - app/controllers/shakha/application_controller.rb
53
+ - app/controllers/shakha/auth_controller.rb
54
+ - app/controllers/shakha/jwks_controller.rb
55
+ - app/controllers/shakha/openid_controller.rb
56
+ - app/controllers/shakha/session_controller.rb
57
+ - app/models/shakha/client.rb
58
+ - app/models/shakha/session.rb
59
+ - app/models/shakha/user.rb
60
+ - app/views/shakha/auth/callback.html.erb
61
+ - app/views/shakha/auth/new.html.erb
62
+ - app/views/shakha/errors/show.html.erb
63
+ - app/views/shakha/layouts/shakha.html.erb
64
+ - generators/shakha/install_generator.rb
65
+ - generators/shakha/templates/initializer.rb.erb
66
+ - generators/shakha/templates/migration.rb.erb
67
+ - lib/shakha.rb
68
+ - lib/shakha/config.rb
69
+ - lib/shakha/controller_helpers.rb
70
+ - lib/shakha/engine.rb
71
+ - lib/shakha/error_handler.rb
72
+ - lib/shakha/jwt_handler.rb
73
+ - lib/shakha/middleware.rb
74
+ - lib/shakha/pairwise.rb
75
+ - lib/shakha/pkce.rb
76
+ - lib/shakha/version.rb
77
+ homepage: https://shakha.dev
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ homepage_uri: https://shakha.dev
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.6.9
97
+ specification_version: 4
98
+ summary: Minimal auth broker for Google OAuth with PKCE and pairwise subjects
99
+ test_files: []