Skip to content

Commit d394c12

Browse files
committed
FEATURE: Support latest version of ruby-jwt to support core changes
This change is not backwards compatible. If you install the plugin on an earlier version of Discourse, the plugin will not initialize.
1 parent 88fdf7b commit d394c12

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/omniauth_open_id_connect.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,23 @@ def id_token_info
104104
# Verify the claims in the JWT
105105
# The signature does not need to be verified because the
106106
# token was acquired via a direct server-server connection to the issuer
107-
@id_token_info ||= JWT.decode(
108-
access_token['id_token'], nil, false,
109-
:verify_iss => true,
110-
'iss' => options[:client_options][:site],
111-
:verify_aud => true,
112-
'aud' => options.client_id,
113-
:verify_sub => false,
114-
:verify_expiration => true,
115-
:verify_not_before => true,
116-
:verify_iat => true,
117-
:verify_jti => false
118-
).first
107+
@id_token_info ||= begin
108+
decoded = JWT.decode(access_token['id_token'], nil, false).first
109+
110+
JWT::Verify.verify_claims(decoded,
111+
verify_iss: true,
112+
iss: options[:client_options][:site],
113+
verify_aud: true,
114+
aud: options.client_id,
115+
verify_sub: false,
116+
verify_expiration: true,
117+
verify_not_before: true,
118+
verify_iat: true,
119+
verify_jti: false
120+
)
121+
122+
decoded
123+
end
119124
end
120125

121126
def userinfo_response

plugin.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@ def register_middleware(omniauth)
5454
end
5555
end
5656

57-
auth_provider authenticator: OpenIDConnectAuthenticator.new(),
58-
full_screen_login: true
57+
# TODO: remove this check once Discourse 2.2 is released
58+
if Gem.loaded_specs['jwt'].version > Gem::Version.create('2.0')
59+
auth_provider authenticator: OpenIDConnectAuthenticator.new(),
60+
full_screen_login: true
61+
else
62+
STDERR.puts "WARNING: discourse-openid-connect requires Discourse v2.2.0.beta7 or above. The plugin will not be loaded."
63+
end

0 commit comments

Comments
 (0)