himari 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d532b382f36d5465772fc09e18feebf0a29db47365e2f5fbd3e83cec7eaa6c4b
4
- data.tar.gz: cf9632d941835355bea9cde2435ad6e9993cb278d306e8d5888fc804053cce32
3
+ metadata.gz: 5b8557a7f7d75db91d61c20e931bfa9d05d832541b4fb9fdc05055491568e4ec
4
+ data.tar.gz: c50b5396fa19b2c03b2b4115d495f3f96a688016a4c8d3fb9b1833ef10de13b7
5
5
  SHA512:
6
- metadata.gz: bb564663bea0c6c39cc0a81d4db848f1e7142b9e2d89ddc34d4b2550d99c44dfc6340dddc239d701ac53d53f762519388095a7806b68d29b675215785cbaf90a
7
- data.tar.gz: db75ed71b1daef3ae8d3ebbcdf85518c27b9be0fea0a3cc18ca7906271253ac16abc6635c44c5f1b03d3e2a6c3354d02611133e6d71ac4a3e5d6019f756bce47
6
+ metadata.gz: eac9157e67de6f6c2538b36f7d6a55e62f1d3a7e3837e72a23d0b6d407a40a2004f7a7fee8c71b036c709daf6be970a75ae45118c116bbd4ab1a085eb23af137
7
+ data.tar.gz: b40f7ed7a033f312871a191398ba1d74f376c89d634666b4b076a05666a66309d8886d0bd3d441144d1fea781847e6f020fa9ec39a079ac1ef3f48f9f332efba
@@ -44,6 +44,11 @@ module Himari
44
44
 
45
45
  attr_reader :handle, :client_id, :claims, :expiry
46
46
 
47
+ def userinfo
48
+ claims.merge(
49
+ aud: client_id,
50
+ )
51
+ end
47
52
 
48
53
  def to_bearer
49
54
  Bearer.new(
@@ -2,19 +2,20 @@ require 'digest/sha2'
2
2
 
3
3
  module Himari
4
4
  class ClientRegistration
5
- def initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil)
5
+ def initialize(name:, id:, secret: nil, secret_hash: nil, redirect_uris:, preferred_key_group: nil, require_pkce: false)
6
6
  @name = name
7
7
  @id = id
8
8
  @secret = secret
9
9
  @secret_hash = secret_hash
10
10
  @redirect_uris = redirect_uris
11
11
  @preferred_key_group = preferred_key_group
12
+ @require_pkce = require_pkce
12
13
 
13
14
  raise ArgumentError, "name starts with '_' is reserved" if @name&.start_with?('_')
14
15
  raise ArgumentError, "either secret or secret_hash must be present" if !@secret && !@secret_hash
15
16
  end
16
17
 
17
- attr_reader :name, :id, :redirect_uris, :preferred_key_group
18
+ attr_reader :name, :id, :redirect_uris, :preferred_key_group, :require_pkce
18
19
 
19
20
  def secret_hash
20
21
  @secret_hash ||= Digest::SHA384.hexdigest(secret)
@@ -58,6 +58,8 @@ module Himari
58
58
  @authz.code_challenge = req.code_challenge
59
59
  @authz.code_challenge_method = req.code_challenge_method || 'plain'
60
60
  next req.bad_request!(:invalid_request, 'Invalid PKCE parameters') unless @authz.pkce_valid_request?
61
+ elsif @client.require_pkce
62
+ next req.bad_request!(:invalid_request, 'PKCE is mandatory')
61
63
  end
62
64
 
63
65
  @storage.put_authorization(@authz)
@@ -57,11 +57,19 @@ module Himari
57
57
  @logger&.warn(Himari::LogLine.new('OidcTokenEndpoint: invalid_grant, expired grant', req: env['himari.request_as_log'], client: client.as_log, grant: authz.as_log))
58
58
  next req.invalid_grant!
59
59
  end
60
- if authz.pkce? && !req.verify_code_verifier!(authz.code_challenge, authz.code_challenge_method)
61
- # :nocov:
62
- @logger&.warn(Himari::LogLine.new('OidcTokenEndpoint: invalid_grant, invalid pkce', req: env['himari.request_as_log'], client: client.as_log, grant: authz.as_log))
60
+
61
+ if authz.pkce?
62
+ if req.verify_code_verifier!(authz.code_challenge, authz.code_challenge_method)
63
+ # do nothing
64
+ else
65
+ # :nocov:
66
+ @logger&.warn(Himari::LogLine.new('OidcTokenEndpoint: invalid_grant, invalid pkce', req: env['himari.request_as_log'], client: client.as_log, grant: authz.as_log))
67
+ next req.invalid_grant!
68
+ # :nocov:
69
+ end
70
+ elsif client.require_pkce
71
+ @logger&.warn(Himari::LogLine.new('OidcTokenEndpoint: invalid_grant, pkce is mandatory', req: env['himari.request_as_log'], client: client.as_log, grant: authz.as_log))
63
72
  next req.invalid_grant!
64
- # :nocov:
65
73
  end
66
74
 
67
75
  token = AccessToken.from_authz(authz)
@@ -45,7 +45,7 @@ module Himari
45
45
  [
46
46
  200,
47
47
  {'Content-Type' => 'application/json; charset=utf-8'},
48
- [JSON.pretty_generate(token.claims), "\n"],
48
+ [JSON.pretty_generate(token.userinfo), "\n"],
49
49
  ]
50
50
  rescue InvalidToken, Himari::TokenString::SecretIncorrect, Himari::TokenString::InvalidFormat, Himari::TokenString::TokenExpired => e
51
51
  @logger&.warn(Himari::LogLine.new('OidcUserinfoEndpoint: invalid_token', req: @env['himari.request_as_log'], err: e.class.inspect, token: token&.as_log))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Himari
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: himari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sorah Fukumori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-26 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubygems_version: 3.1.6
169
+ rubygems_version: 3.4.6
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Small OIDC IdP for small teams - Omniauth to OIDC