diff --git a/packages/rocketchat-custom-oauth/custom_oauth_server.coffee b/packages/rocketchat-custom-oauth/custom_oauth_server.coffee index f2aa590d56b1..0b7237c29921 100644 --- a/packages/rocketchat-custom-oauth/custom_oauth_server.coffee +++ b/packages/rocketchat-custom-oauth/custom_oauth_server.coffee @@ -36,6 +36,7 @@ class CustomOAuth @serverURL = options.serverURL @tokenPath = options.tokenPath @identityPath = options.identityPath + @tokenSentVia = options.tokenSentVia if not /^https?:\/\/.+/.test @tokenPath @tokenPath = @serverURL + @tokenPath @@ -75,13 +76,19 @@ class CustomOAuth return response.data.access_token getIdentity: (accessToken) -> + params = {} + headers = + 'User-Agent': @userAgent # http://doc.gitlab.com/ce/api/users.html#Current-user + + if @accessTokenSentVia is 'header' + headers['Authorization'] = 'Bearer ' + accessToken + else + params['access_token'] = accessToken + try response = HTTP.get @identityPath, - headers: - 'User-Agent': @userAgent # http://doc.gitlab.com/ce/api/users.html#Current-user - 'Authorization': 'Bearer ' + accessToken - params: - access_token: accessToken + headers: headers + params: params if response.data return response.data diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index e4720b79ccaf..ea605c49e0d1 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -33,6 +33,7 @@ "Accounts_iframe_url" : "Iframe Url", "Accounts_LoginExpiration" : "Login Expiration in Days", "Accounts_ManuallyApproveNewUsers" : "Manually Approve New Users", + "Accounts_OAuth_Custom_Token_Sent_Via" : "Token Sent Via", "Accounts_OAuth_Custom_Authorize_Path" : "Authorize Path", "Accounts_OAuth_Custom_Button_Color" : "Button Color", "Accounts_OAuth_Custom_Button_Label_Color" : "Button Text Color", @@ -338,6 +339,7 @@ "GoogleTagManager_id" : "Google Tag Manager Id", "Has_more" : "Has more", "Have_your_own_chat" : "Have your own web chat. Developed with Meteor.com, the Rocket.Chat is a great solution for developers looking forward to build and evolve their own chat platform.", + "Header" : "Header", "Hidden" : "Hidden", "Hide_Group_Warning" : "Are you sure you want to hide the group \"%s\"?", "Hide_Private_Warning" : "Are you sure you want to hide the discussion with \"%s\"?", @@ -646,6 +648,7 @@ "Password" : "Password", "Password_Change_Disabled" : "Your Rocket.Chat administrator has disabled the changing of passwords", "Password_changed_successfully" : "Password changed successfully", + "Payload" : "Payload", "People" : "People", "Permissions" : "Permissions", "Pin_Message" : "Pin Message", diff --git a/packages/rocketchat-lib/server/methods/addOAuthService.coffee b/packages/rocketchat-lib/server/methods/addOAuthService.coffee index a86c993f0fd7..3c2548135e69 100644 --- a/packages/rocketchat-lib/server/methods/addOAuthService.coffee +++ b/packages/rocketchat-lib/server/methods/addOAuthService.coffee @@ -8,14 +8,15 @@ Meteor.methods name = name.toLowerCase().replace(/[^a-z0-9]/g, '') name = s.capitalize(name) - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}" , false , { type: 'boolean', group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Enable', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_url" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_URL', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_token_path" , '/oauth/token' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Token_Path', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_identity_path" , '/me' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Identity_Path', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_authorize_path" , '/oauth/authorize', { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Authorize_Path', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_id" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_id', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_secret" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Secret', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_login_style" , 'popup' , { type: 'select' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Login_Style', persistent: true, values: [ { key: 'redirect', i18nLabel: 'Redirect' }, { key: 'popup', i18nLabel: 'Popup' }, { key: '', i18nLabel: 'Default' } ] } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_label_text" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Label_Text', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_label_color", '#FFFFFF' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Label_Color', persistent: true } - RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_color" , '#13679A' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Color', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}" , false , { type: 'boolean', group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Enable', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_url" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_URL', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_token_path" , '/oauth/token' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Token_Path', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_identity_path" , '/me' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Identity_Path', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_authorize_path" , '/oauth/authorize', { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Authorize_Path', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_token_sent_via" , 'payload' , { type: 'select' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Token_Sent_Via', persistent: true, values: [ { key: 'header', i18nLabel: 'Header' }, { key: 'payload', i18nLabel: 'Payload' } ] } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_id" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_id', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_secret" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Secret', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_login_style" , 'popup' , { type: 'select' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Login_Style', persistent: true, values: [ { key: 'redirect', i18nLabel: 'Redirect' }, { key: 'popup', i18nLabel: 'Popup' }, { key: '', i18nLabel: 'Default' } ] } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_label_text" , '' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Label_Text', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_label_color" , '#FFFFFF' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Label_Color', persistent: true } + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_button_color" , '#13679A' , { type: 'string' , group: 'OAuth', section: "Custom OAuth: #{name}", i18nLabel: 'Accounts_OAuth_Custom_Button_Color', persistent: true } diff --git a/packages/rocketchat-lib/server/methods/removeOAuthService.coffee b/packages/rocketchat-lib/server/methods/removeOAuthService.coffee index eb22fe04fd32..4b28a7a289da 100644 --- a/packages/rocketchat-lib/server/methods/removeOAuthService.coffee +++ b/packages/rocketchat-lib/server/methods/removeOAuthService.coffee @@ -13,6 +13,7 @@ Meteor.methods RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_token_path" RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_identity_path" RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_authorize_path" + RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_token_sent_via" RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_id" RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_secret" RocketChat.settings.removeById "Accounts_OAuth_Custom_#{name}_button_label_text" diff --git a/packages/rocketchat-lib/server/startup/oAuthServicesUpdate.coffee b/packages/rocketchat-lib/server/startup/oAuthServicesUpdate.coffee index 4a5fbbdf96e2..780a1b963f80 100644 --- a/packages/rocketchat-lib/server/startup/oAuthServicesUpdate.coffee +++ b/packages/rocketchat-lib/server/startup/oAuthServicesUpdate.coffee @@ -35,12 +35,14 @@ OAuthServicesUpdate = -> data.buttonLabelColor = RocketChat.models.Settings.findOneById("#{service._id}_button_label_color")?.value data.loginStyle = RocketChat.models.Settings.findOneById("#{service._id}_login_style")?.value data.buttonColor = RocketChat.models.Settings.findOneById("#{service._id}_button_color")?.value + data.tokenSentVia = RocketChat.models.Settings.findOneById("#{service._id}_token_sent_via")?.value new CustomOAuth serviceName.toLowerCase(), serverURL: data.serverURL tokenPath: data.tokenPath identityPath: data.identityPath authorizePath: data.authorizePath loginStyle: data.loginStyle + tokenSentVia: data.tokenSentVia if serviceName is 'Facebook' data.appId = data.clientId diff --git a/server/startup/migrations/v40.js b/server/startup/migrations/v40.js new file mode 100644 index 000000000000..aded822962ce --- /dev/null +++ b/server/startup/migrations/v40.js @@ -0,0 +1,39 @@ +RocketChat.Migrations.add({ + version: 40, + up: function() { + RocketChat.models.Settings.find({ _id: /Accounts_OAuth_Custom_/, i18nLabel: 'Accounts_OAuth_Custom_Enable' }).forEach(function(customOauth) { + var parts = customOauth._id.split('_'); + var name = parts[3]; + var id = 'Accounts_OAuth_Custom_' + name + '_token_sent_via'; + if (!RocketChat.models.Settings.findOne( { _id: id } )) { + RocketChat.models.Settings.insert({ + '_id': id, + 'type': 'select', + 'group': 'OAuth', + 'section': 'Custom OAuth: ' + name, + 'i18nLabel': 'Accounts_OAuth_Custom_Token_Sent_Via', + 'persistent': true, + 'values': [ + { + 'key': 'header', + 'i18nLabel': 'Header' + }, + { + 'key': 'payload', + 'i18nLabel': 'Payload' + } + ], + 'packageValue': 'payload', + 'valueSource': 'packageValue', + 'ts': new Date(), + 'hidden': false, + 'blocked': false, + 'sorter': 255, + 'i18nDescription': 'Accounts_OAuth_Custom_' + name + '_token_sent_via_Description', + 'createdAt': new Date(), + 'value': 'payload' + }); + } + }); + } +});