This repository was archived by the owner on Jul 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Updates and Rename #22
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| en: | ||
| site_settings: | ||
| office365_enabled: 'Allow users to authenticate using Office365?' | ||
| office365_client_id: 'Office365 App ID/Client Id (need one? visit <a href="https://apps.dev.microsoft.com/#/appList">https://apps.dev.microsoft.com/#/appList</a>)' | ||
| office365_secret: 'Office365 Secret Password' | ||
| microsoft_auth_enabled: 'Allow users to authenticate using Microsoft?' | ||
| microsoft_auth_client_id: 'Microsoft App ID/Client Id (need one? visit <a href="https://apps.dev.microsoft.com/#/appList">https://apps.dev.microsoft.com/#/appList</a>)' | ||
| microsoft_auth_client_secret: 'Microsoft Secret Password' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| plugins: | ||
| office365_enabled: | ||
| microsoft_auth_enabled: | ||
| client: true | ||
| default: false | ||
| office365_client_id: | ||
| microsoft_auth_client_id: | ||
| client: false | ||
| default: '' | ||
| office365_secret: | ||
| microsoft_auth_client_secret: | ||
| client: false | ||
| default: '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class MigrateOffice365UserInfo < ActiveRecord::Migration[6.1] | ||
| def up | ||
| execute <<~SQL | ||
| INSERT INTO user_associated_accounts ( | ||
| provider_name, | ||
| provider_uid, | ||
| user_id, | ||
| info, | ||
| last_used, | ||
| created_at, | ||
| updated_at | ||
| ) SELECT | ||
| 'microsoft_office365', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, we can't change it without a lot of pain |
||
| uid, | ||
| user_id, | ||
| json_build_object('email', email, 'name', name), | ||
| updated_at, | ||
| created_at, | ||
| updated_at | ||
| FROM oauth2_user_infos | ||
| WHERE provider = 'microsoft_office365' | ||
| SQL | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
23 changes: 23 additions & 0 deletions
23
db/migrate/20211202140128_rename_office365_to_microsoft.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # frozen_string_literal: true | ||
| class RenameOffice365ToMicrosoft < ActiveRecord::Migration[6.1] | ||
| CHANGES = [ | ||
| ["office365_enabled", "microsoft_auth_enabled"], | ||
| ["office365_client_id", "microsoft_auth_client_id"], | ||
| ["office365_secret", "microsoft_auth_client_secret"], | ||
| ] | ||
|
|
||
| def up | ||
| CHANGES.each do |old, new| | ||
| DB.exec(<<~SQL, old_name: old, new_name: new) | ||
| INSERT INTO site_settings (name, data_type, value, created_at, updated_at) | ||
| SELECT :new_name, data_type, value, created_at, updated_at | ||
| FROM site_settings | ||
| WHERE name = :old_name | ||
| SQL | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end |
10 changes: 10 additions & 0 deletions
10
db/post_migrate/20211202141030_remove_old_office365_site_settings.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
| class RemoveOldOffice365SiteSettings < ActiveRecord::Migration[6.1] | ||
| def up | ||
| execute "DELETE FROM site_settings WHERE name IN ('office365_enabled', 'office365_client_id', 'office365_secret')" | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # name: discourse-plugin-office365-auth | ||
| # about: Enable Login via Office365 | ||
| # version: 0.0.1 | ||
| # name: discourse-microsoft-auth | ||
| # about: Enable Login via Microsoft Identity Platform | ||
| # version: 1.0 | ||
| # authors: Matthew Wilkin | ||
| # url: https://github.com/discourse/discourse-plugin-office365-auth | ||
| # url: https://github.com/discourse/discourse-microsoft-auth | ||
|
|
||
| require 'auth/oauth2_authenticator' | ||
| require File.expand_path('../omniauth-microsoft365.rb', __FILE__) | ||
| require_relative "lib/omniauth-microsoft365" | ||
|
|
||
| enabled_site_setting :office365_enabled | ||
| enabled_site_setting :microsoft_auth_enabled | ||
|
|
||
| class Office365Authenticator < ::Auth::OAuth2Authenticator | ||
| PLUGIN_NAME = 'oauth-office365' | ||
| register_svg_icon "fab-microsoft" | ||
|
|
||
| class ::MicrosoftAuthenticator < ::Auth::ManagedAuthenticator | ||
| def name | ||
| 'microsoft_office365' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the authenticator still called
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, we can't change it without a lot of pain |
||
| end | ||
|
|
||
| def after_authenticate(auth_token) | ||
| result = super | ||
|
|
||
| if result.user && result.email && (result.user.email != result.email) | ||
| begin | ||
| result.user.primary_email.update!(email: result.email) | ||
| rescue | ||
| used_by = User.find_by_email(result.email)&.username | ||
| Rails.loger.warn("FAILED to update email for #{user.username} to #{result.email} cause it is in use by #{used_by}") | ||
| end | ||
| end | ||
|
|
||
| result | ||
| end | ||
|
|
||
| def register_middleware(omniauth) | ||
| omniauth.provider :microsoft_office365, | ||
| setup: lambda { |env| | ||
| strategy = env['omniauth.strategy'] | ||
| strategy.options[:client_id] = SiteSetting.office365_client_id | ||
| strategy.options[:client_secret] = SiteSetting.office365_secret | ||
| strategy.options[:client_id] = SiteSetting.microsoft_auth_client_id | ||
| strategy.options[:client_secret] = SiteSetting.microsoft_auth_client_secret | ||
| } | ||
| end | ||
|
|
||
| def enabled? | ||
| SiteSetting.office365_enabled | ||
| SiteSetting.microsoft_auth_enabled | ||
| end | ||
| end | ||
|
|
||
| auth_provider enabled_setting: "office365_enabled", | ||
| frame_width: 920, | ||
| frame_height: 800, | ||
| authenticator: Office365Authenticator.new( | ||
| 'microsoft_office365', | ||
| trusted: true, | ||
| auto_create_account: true | ||
| ) | ||
|
|
||
| register_css <<CSS | ||
| .btn-social.microsoft_office365 { | ||
| background: #EB3D01; | ||
| } | ||
| CSS | ||
| auth_provider authenticator: MicrosoftAuthenticator.new, | ||
| icon: "fab-microsoft" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for not renaming the
microsoft_office365key?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the name of the authenticator is tied to the 'callback url'. If we change it, everyone would have to update their config with microsoft. I don't think it's worth that pain.