-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.rb
67 lines (53 loc) · 1.59 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
# name: discourse-roblox-auth
# about: Allows users to sign in with their Roblox account
# version: 0.0.1
# authors: Regalijan
# url: https://github.com/Regalijan/discourse-roblox-auth
enabled_site_setting :enable_roblox_logins
require 'base64'
require 'net/http'
require_relative 'lib/validators/EnableRobloxOpenCloudOAuth'
class RobloxAuthenticator < Auth::ManagedAuthenticator
class RobloxStrategy < OmniAuth::Strategies::OAuth2
option :name, 'roblox'
option :scope, 'openid profile'
option :client_options,
site: 'https://apis.roblox.com/oauth/v1/',
authorize_url: 'authorize',
token_url: 'token'
option :authorize_options, %i[scope]
uid { raw_info['sub'] }
info do
{
name: raw_info['nickname'],
image: raw_info['picture']
}
end
def callback_url
full_host + script_name + callback_path
end
def raw_info
@raw_info ||= JSON.parse(
Base64.urlsafe_decode64(
access_token['id_token'].split('.')[1]
)
)
end
end
def name
'roblox'
end
def enabled?
SiteSetting.enable_roblox_logins?
end
def register_middleware(omniauth)
omniauth.provider RobloxStrategy,
setup: lambda { |env|
strategy = env['omniauth.strategy']
strategy.options[:client_id] = SiteSetting.roblox_client_id
strategy.options[:client_secret] = SiteSetting.roblox_secret
}
end
end
auth_provider authenticator: RobloxAuthenticator.new