-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplugin.rb
36 lines (30 loc) · 1.04 KB
/
plugin.rb
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
# frozen_string_literal: true
# name: discourse-jwt
# about: JSON Web Tokens Auth Provider
# version: 0.1
# author: Robin Ward
gem "omniauth-jwt2", "0.1.0", require: false
require "omniauth/jwt"
class JWTAuthenticator < Auth::ManagedAuthenticator
def name
"jwt"
end
def register_middleware(omniauth)
omniauth.provider :jwt,
name: "jwt",
uid_claim: "id",
required_claims: %w[id email name],
setup:
lambda { |env|
opts = env["omniauth.strategy"].options
opts[:secret] = SiteSetting.jwt_secret
opts[:auth_url] = SiteSetting.jwt_auth_url
}
end
def enabled?
# Check the global setting for backwards-compatibility.
# When this plugin used only global settings, there was no separate enable setting
SiteSetting.jwt_enabled || GlobalSetting.try(:jwt_auth_url)
end
end
auth_provider authenticator: JWTAuthenticator.new