Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Custom OAuth: Not able to set different token place for routes #9034

Merged
merged 1 commit into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ export class CustomOAuth {
this.tokenPath = options.tokenPath;
this.identityPath = options.identityPath;
this.tokenSentVia = options.tokenSentVia;
this.identityTokenSentVia = options.identityTokenSentVia;
this.usernameField = (options.usernameField || '').trim();
this.mergeUsers = options.mergeUsers;

if (this.identityTokenSentVia == null || this.identityTokenSentVia === 'default') {
this.identityTokenSentVia = this.tokenSentVia;
}

if (!/^https?:\/\/.+/.test(this.tokenPath)) {
this.tokenPath = this.serverURL + this.tokenPath;
}
Expand Down Expand Up @@ -127,7 +132,7 @@ export class CustomOAuth {
'User-Agent': this.userAgent // http://doc.gitlab.com/ce/api/users.html#Current-user
};

if (this.tokenSentVia === 'header') {
if (this.identityTokenSentVia === 'header') {
headers['Authorization'] = `Bearer ${ accessToken }`;
} else {
params['access_token'] = accessToken;
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"Accounts_OAuth_Custom_Secret": "Secret",
"Accounts_OAuth_Custom_Token_Path": "Token Path",
"Accounts_OAuth_Custom_Token_Sent_Via": "Token Sent Via",
"Accounts_OAuth_Custom_Identity_Token_Sent_Via": "Identity Token Sent Via",
"Accounts_OAuth_Custom_Username_Field": "Username field",
"Accounts_OAuth_Drupal": "Drupal Login Enabled",
"Accounts_OAuth_Drupal_callback_url": "Drupal oAuth2 Redirect URI",
Expand Down Expand Up @@ -1554,6 +1555,7 @@
"run-migration_description": "Permission to run the migrations",
"Running_Instances": "Running Instances",
"S_new_messages_since_s": "%s new messages since %s",
"Same_As_Token_Sent_Via" : "Same as \"Token Sent Via\"",
"Same_Style_For_Mentions": "Same style for mentions",
"SAML": "SAML",
"SAML_Custom_Cert": "Custom Certificate",
Expand Down
31 changes: 16 additions & 15 deletions packages/rocketchat-lib/server/methods/addOAuthService.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Meteor.methods({
RocketChat.settings.removeById(`Accounts_OAuth_Custom-${ name }-authorize_path`);
RocketChat.settings.removeById(`Accounts_OAuth_Custom-${ name }-scope`);
RocketChat.settings.removeById(`Accounts_OAuth_Custom-${ name }-token_sent_via`);
RocketChat.settings.removeById(`Accounts_OAuth_Custom-${ name }-identity_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`);
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/server/startup/oAuthServicesUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function _OAuthServicesUpdate() {
data.loginStyle = RocketChat.settings.get(`${ service.key }-login_style`);
data.buttonColor = RocketChat.settings.get(`${ service.key }-button_color`);
data.tokenSentVia = RocketChat.settings.get(`${ service.key }-token_sent_via`);
data.identityTokenSentVia = RocketChat.settings.get(`${ service.key }-identity_token_sent_via`);
data.usernameField = RocketChat.settings.get(`${ service.key }-username_field`);
data.mergeUsers = RocketChat.settings.get(`${ service.key }-merge_users`);
new CustomOAuth(serviceName.toLowerCase(), {
Expand All @@ -49,6 +50,7 @@ function _OAuthServicesUpdate() {
scope: data.scope,
loginStyle: data.loginStyle,
tokenSentVia: data.tokenSentVia,
identityTokenSentVia: data.identityTokenSentVia,
usernameField: data.usernameField,
mergeUsers: data.mergeUsers
});
Expand Down