Skip to content

Commit 0f46b51

Browse files
committed
First take
1 parent d32e7af commit 0f46b51

File tree

22 files changed

+178
-4084
lines changed

22 files changed

+178
-4084
lines changed

.DS_Store

6 KB
Binary file not shown.

.discourse-compatibility

Whitespace-only changes.

.npmrc

Lines changed: 0 additions & 2 deletions
This file was deleted.

.prettierrc.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

.template-lintrc.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# **Plugin Name** Plugin
1+
# **Discourse Login Client** Plugin
22

33
**Plugin Summary**
44

5-
For more information, please see: **url to meta topic**
5+
Test plugin for unified login.

app/.gitkeep

Whitespace-only changes.

app/controllers/my_plugin_module/examples_controller.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

assets/javascripts/.gitkeep

Whitespace-only changes.

assets/stylesheets/.gitkeep

Whitespace-only changes.

config/locales/client.en.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ en:
33
admin:
44
site_settings:
55
categories:
6-
TODO_plugin_name: "Plugin Name"
6+
discourse_login_client_enabled: "Discourse Login Client"
77
js:
8-
discourse_plugin_name:
9-
placeholder: placeholder
8+
login:
9+
discourse_login:
10+
name: "Discourse Login"

config/routes.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/settings.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
TODO_plugin_name:
2-
plugin_name_enabled:
1+
plugins:
2+
discourse_login_client_enabled:
33
default: false
4-
client: true
4+
client: false
5+
discourse_login_client_id:
6+
default: ""
7+
client: false
8+
discourse_login_client_secret:
9+
default: ""
10+
client: false
11+
secret: true
12+
discourse_login_debug_auth:
13+
default: false
14+
client: false
15+
discourse_login_client_button_title:
16+
default: "Discourse Login"
17+
client: false
18+
discourse_login_client_url:
19+
default: ""
20+
hidden: true
21+
client: false

db/.gitkeep

Whitespace-only changes.

eslint.config.mjs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# frozen_string_literal: true
2+
3+
class DiscourseLoginClientAuthenticator < Auth::ManagedAuthenticator
4+
class DiscourseLoginClientStrategy < ::OmniAuth::Strategies::OAuth2
5+
option :name, "discourse_login"
6+
7+
option :client_options,
8+
authorize_url: "/oauth/authorize",
9+
token_url: "/oauth/token",
10+
auth_scheme: :basic_auth
11+
12+
option :authorize_options, [:scope]
13+
14+
uid { access_token.params["info"]["uuid"] }
15+
16+
info do
17+
{
18+
username: access_token.params["info"]["username"],
19+
name: access_token.params["info"]["username"],
20+
email: access_token.params["info"]["email"],
21+
# image: for avatar?
22+
}
23+
end
24+
25+
def callback_url
26+
Discourse.base_url_no_prefix + script_name + callback_path
27+
end
28+
end
29+
30+
def name
31+
"discourse_login"
32+
end
33+
34+
def can_revoke?
35+
true
36+
end
37+
38+
def can_connect_existing_user?
39+
true
40+
end
41+
42+
def base_url
43+
SiteSetting.discourse_login_client_url.presence || "https://logindemo.discourse.group"
44+
end
45+
46+
def register_middleware(omniauth)
47+
omniauth.provider DiscourseLoginClientStrategy,
48+
setup:
49+
lambda { |env|
50+
opts = env["omniauth.strategy"].options
51+
opts[:client_id] = SiteSetting.discourse_login_client_id
52+
opts[:client_secret] = SiteSetting.discourse_login_client_secret
53+
opts[:client_options][:site] = base_url
54+
opts[:scope] = "read"
55+
}
56+
end
57+
58+
def primary_email_verified?(auth_token)
59+
true # email will be verified at source
60+
end
61+
62+
def always_update_user_email?
63+
false # not sure
64+
end
65+
66+
def enabled?
67+
SiteSetting.discourse_login_client_enabled && SiteSetting.discourse_login_client_id &&
68+
SiteSetting.discourse_login_client_secret
69+
end
70+
end

lib/my_plugin_module/engine.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

plugin.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# frozen_string_literal: true
22

3-
# name: discourse-plugin-name
4-
# about: TODO
5-
# meta_topic_id: TODO
3+
# name: discourse-login-client
4+
# about: Test plugin
5+
# meta_topic_id: N/A
66
# version: 0.0.1
77
# authors: Discourse
88
# url: TODO
9-
# required_version: 2.7.0
9+
# required_version: 3.3.0
1010

11-
enabled_site_setting :plugin_name_enabled
11+
require_relative "lib/discourse_login_client_authenticator"
1212

13-
module ::MyPluginModule
14-
PLUGIN_NAME = "discourse-plugin-name"
15-
end
13+
enabled_site_setting :discourse_login_client_enabled
1614

17-
require_relative "lib/my_plugin_module/engine"
18-
19-
after_initialize do
20-
# Code which should run after Rails has finished booting
21-
end
15+
auth_provider title_setting: "discourse_login_client_button_title",
16+
icon: "fab-discourse",
17+
authenticator: DiscourseLoginClientAuthenticator.new

0 commit comments

Comments
 (0)