// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import AdminSettings from './admin_settings.jsx'; import DropdownSetting from './dropdown_setting.jsx'; import SettingsGroup from './settings_group.jsx'; import TextSetting from './text_setting.jsx'; import React from 'react'; import {FormattedHTMLMessage, FormattedMessage} from 'react-intl'; export default class OAuthSettings extends AdminSettings { constructor(props) { super(props); this.getConfigFromState = this.getConfigFromState.bind(this); this.getStateFromConfig = this.getStateFromConfig.bind(this); this.renderSettings = this.renderSettings.bind(this); this.renderOffice365 = this.renderOffice365.bind(this); this.renderGoogle = this.renderGoogle.bind(this); this.renderGitLab = this.renderGitLab.bind(this); this.changeType = this.changeType.bind(this); } getConfigFromState(config) { config.GitLabSettings.Enable = false; config.GoogleSettings.Enable = false; config.Office365Settings.Enable = false; if (this.state.oauthType === Constants.GITLAB_SERVICE) { config.GitLabSettings.Enable = true; config.GitLabSettings.Id = this.state.id; config.GitLabSettings.Secret = this.state.secret; config.GitLabSettings.UserApiEndpoint = this.state.userApiEndpoint; config.GitLabSettings.AuthEndpoint = this.state.authEndpoint; config.GitLabSettings.TokenEndpoint = this.state.tokenEndpoint; } if (this.state.oauthType === Constants.GOOGLE_SERVICE) { config.GoogleSettings.Enable = true; config.GoogleSettings.Id = this.state.id; config.GoogleSettings.Secret = this.state.secret; config.GoogleSettings.UserApiEndpoint = 'https://www.googleapis.com/plus/v1/people/me'; config.GoogleSettings.AuthEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth'; config.GoogleSettings.TokenEndpoint = 'https://www.googleapis.com/oauth2/v4/token'; config.GoogleSettings.Scope = 'profile email'; } if (this.state.oauthType === Constants.OFFICE365_SERVICE) { config.Office365Settings.Enable = true; config.Office365Settings.Id = this.state.id; config.Office365Settings.Secret = this.state.secret; config.Office365Settings.UserApiEndpoint = 'https://graph.microsoft.com/v1.0/me'; config.Office365Settings.AuthEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'; config.Office365Settings.TokenEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; config.Office365Settings.Scope = 'User.Read'; } return config; } getStateFromConfig(config) { this.config = config; let oauthType = 'off'; let settings = {}; if (config.GitLabSettings.Enable) { oauthType = Constants.GITLAB_SERVICE; settings = config.GitLabSettings; } else if (config.GoogleSettings.Enable) { oauthType = Constants.GOOGLE_SERVICE; settings = config.GoogleSettings; } else if (config.Office365Settings.Enable) { oauthType = Constants.OFFICE365_SERVICE; settings = config.Office365Settings; } return { oauthType, id: settings.Id, secret: settings.Secret, userApiEndpoint: settings.UserApiEndpoint, authEndpoint: settings.AuthEndpoint, tokenEndpoint: settings.TokenEndpoint }; } changeType(id, value) { let settings = {}; if (value === Constants.GITLAB_SERVICE) { settings = this.config.GitLabSettings; } else if (value === Constants.GOOGLE_SERVICE) { settings = this.config.GoogleSettings; } else if (value === Constants.OFFICE365_SERVICE) { settings = this.config.Office365Settings; } this.setState({ id: settings.Id, secret: settings.Secret, userApiEndpoint: settings.UserApiEndpoint, authEndpoint: settings.AuthEndpoint, tokenEndpoint: settings.TokenEndpoint }); this.handleChange(id, value); } renderTitle() { return ( ); } renderGoogle() { return (
} placeholder={Utils.localizeMessage('admin.google.clientIdExample', 'Ex "7602141235235-url0fhs1mayfasbmop5qlfns8dh4.apps.googleusercontent.com"')} helpText={ } value={this.state.id} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.google.clientSecretExample', 'Ex "H8sz0Az-dDs2p15-7QzD231"')} helpText={ } value={this.state.secret} onChange={this.handleChange} /> } value='https://www.googleapis.com/plus/v1/people/me' disabled={true} /> } value='https://accounts.google.com/o/oauth2/v2/auth' disabled={true} /> } value='https://www.googleapis.com/oauth2/v4/token' disabled={true} />
); } renderOffice365() { return (
} placeholder={Utils.localizeMessage('admin.office365.clientIdExample', 'Ex "adf3sfa2-ag3f-sn4n-ids0-sh1hdax192qq"')} helpText={ } value={this.state.id} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.office365.clientSecretExample', 'Ex "shAieM47sNBfgl20f8ci294"')} helpText={ } value={this.state.secret} onChange={this.handleChange} /> } value='https://graph.microsoft.com/v1.0/me' disabled={true} /> } value='https://login.microsoftonline.com/common/oauth2/v2.0/authorize' disabled={true} /> } value='https://login.microsoftonline.com/common/oauth2/v2.0/token' disabled={true} />
); } renderGitLab() { return (
} placeholder={Utils.localizeMessage('admin.gitlab.clientIdExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')} helpText={ } value={this.state.id} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.gitlab.clientSecretExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')} helpText={ } value={this.state.secret} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.gitlab.userExample', 'Ex "https:///api/v3/user"')} helpText={ } value={this.state.userApiEndpoint} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.gitlab.authExample', 'Ex "https:///oauth/authorize"')} helpText={ } value={this.state.authEndpoint} onChange={this.handleChange} /> } placeholder={Utils.localizeMessage('admin.gitlab.tokenExample', 'Ex "https:///oauth/token"')} helpText={ } value={this.state.tokenEndpoint} onChange={this.handleChange} />
); } renderSettings() { let contents; let helpText; if (this.state.oauthType === Constants.GITLAB_SERVICE) { contents = this.renderGitLab(); helpText = ( ); } else if (this.state.oauthType === Constants.GOOGLE_SERVICE) { contents = this.renderGoogle(); helpText = ( ); } else if (this.state.oauthType === Constants.OFFICE365_SERVICE) { contents = this.renderOffice365(); helpText = ( ); } const oauthTypes = []; oauthTypes.push({value: 'off', text: Utils.localizeMessage('admin.oauth.off', 'Do not allow sign-in via an OAuth 2.0 provider.')}); oauthTypes.push({value: Constants.GITLAB_SERVICE, text: Utils.localizeMessage('admin.oauth.gitlab', 'GitLab')}); if (global.window.mm_license.IsLicensed === 'true') { if (global.window.mm_license.GoogleOAuth === 'true') { oauthTypes.push({value: Constants.GOOGLE_SERVICE, text: Utils.localizeMessage('admin.oauth.google', 'Google Apps')}); } if (global.window.mm_license.Office365OAuth === 'true') { oauthTypes.push({value: Constants.OFFICE365_SERVICE, text: Utils.localizeMessage('admin.oauth.office365', 'Office 365 (Beta)')}); } } return ( } helpText={helpText} value={this.state.oauthType} onChange={this.changeType} /> {contents} ); } }