File: doorkeeper_configuration.rb

package info (click to toggle)
ruby-doorkeeper-openid-connect 1.7.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 648 kB
  • sloc: ruby: 2,915; makefile: 7; sh: 4
file content (42 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module DoorkeeperConfiguration
  def configure_doorkeeper(signing_key, signing_algorithm)
    Doorkeeper::OpenidConnect.configure do
      signing_key signing_key

      signing_algorithm signing_algorithm

      resource_owner_from_access_token do |access_token|
        User.find_by(id: access_token.resource_owner_id)
      end

      auth_time_from_resource_owner do |resource_owner|
        resource_owner.current_sign_in_at
      end

      subject do |resource_owner|
        resource_owner.id
      end
    end
  end

  def configure_ec
    signing_key = <<~EOL
      -----BEGIN EC PRIVATE KEY-----
      MIHbAgEBBEF9VcxGjPKczrJlE1N3oEpZsauQfDXIjLeini7h4/3+DOKw2VWE4lCU
      rNJJL65EHT+2TriRg2xSb0l0rK/MAFAFraAHBgUrgQQAI6GBiQOBhgAEAeYVvbl3
      zZcFCdE+0msqOowYODjzeXAhjsZKhdNjGlDREvko3UFOw6S43g+s8bvVBmBz3fCo
      dEzFRYQqJVI4UFvFAYJ7GYeBm/Fb6liN53xGASdbRSzF34h4BDSVYzjtQc7I+1LK
      17fwwS3VfQCJwaT6zX33HTrhR4VoUEUJHKwR3dNs
      -----END EC PRIVATE KEY-----
    EOL
    configure_doorkeeper(signing_key, :ES512)
  end

  def configure_hmac
    configure_doorkeeper('the_greatest_secret_key', :HS512)
  end
end

RSpec.configure { |config| config.include DoorkeeperConfiguration }