Commit 2abd9098 authored by Ryan Wang's avatar Ryan Wang Committed by Joram Wilander
Browse files

[PLT-7778] Pre-populate token/API endpoints for GitLab (#130)

parent 6e85f211
......@@ -16,8 +16,8 @@ export default class GitLabSettings extends AdminSettings {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
this.updateGitLabUrl = this.updateGitLabUrl.bind(this);
}
getConfigFromState(config) {
......@@ -36,12 +36,28 @@ export default class GitLabSettings extends AdminSettings {
enable: config.GitLabSettings.Enable,
id: config.GitLabSettings.Id,
secret: config.GitLabSettings.Secret,
gitLabUrl: config.GitLabSettings.UserApiEndpoint.replace('/api/v4/user', ''),
userApiEndpoint: config.GitLabSettings.UserApiEndpoint,
authEndpoint: config.GitLabSettings.AuthEndpoint,
tokenEndpoint: config.GitLabSettings.TokenEndpoint
};
}
updateGitLabUrl(id, value) {
let trimmedValue = value;
if (value.endsWith('/')) {
trimmedValue = value.slice(0, -1);
}
this.setState({
saveNeeded: true,
gitLabUrl: value,
userApiEndpoint: trimmedValue + '/api/v4/user',
authEndpoint: trimmedValue + '/oauth/authorize',
tokenEndpoint: trimmedValue + '/oauth/token'
});
}
renderTitle() {
return (
<FormattedMessage
......@@ -117,42 +133,47 @@ export default class GitLabSettings extends AdminSettings {
disabled={!this.state.enable}
/>
<TextSetting
id='userApiEndpoint'
id='gitlabUrl'
label={
<FormattedMessage
id='admin.gitlab.userTitle'
defaultMessage='User API Endpoint:'
id='admin.gitlab.siteUrl'
defaultMessage='GitLab Site URL:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.userExample', 'Ex "https://<your-gitlab-url>/api/v4/user"')}
placeholder={Utils.localizeMessage('admin.gitlab.siteUrlExample', 'E.g.: https://')}
helpText={
<FormattedMessage
id='admin.gitlab.userDescription'
defaultMessage='Enter https://<your-gitlab-url>/api/v4/user. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
id='admin.gitab.siteUrlDescription'
defaultMessage='Enter the URL of your GitLab instance, e.g. https://example.com:3000. If your GitLab instance is not set up with SSL, start the URL with http:// instead of https://.'
/>
}
value={this.state.userApiEndpoint}
onChange={this.handleChange}
value={this.state.gitLabUrl}
onChange={this.updateGitLabUrl}
disabled={!this.state.enable}
/>
<TextSetting
id='authEndpoint'
id='userApiEndpoint'
label={
<FormattedMessage
id='admin.gitlab.authTitle'
defaultMessage='Auth Endpoint:'
id='admin.gitlab.userTitle'
defaultMessage='User API Endpoint:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.authExample', 'Ex "https://<your-gitlab-url>/oauth/authorize"')}
helpText={
placeholder={''}
value={this.state.userApiEndpoint}
disabled={true}
/>
<TextSetting
id='authEndpoint'
label={
<FormattedMessage
id='admin.gitlab.authDescription'
defaultMessage='Enter https://<your-gitlab-url>/oauth/authorize (example https://example.com:3000/oauth/authorize). Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
id='admin.gitlab.authTitle'
defaultMessage='Auth Endpoint:'
/>
}
placeholder={''}
value={this.state.authEndpoint}
onChange={this.handleChange}
disabled={!this.state.enable}
disabled={true}
/>
<TextSetting
id='tokenEndpoint'
......@@ -162,16 +183,9 @@ export default class GitLabSettings extends AdminSettings {
defaultMessage='Token Endpoint:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.tokenExample', 'Ex "https://<your-gitlab-url>/oauth/token"')}
helpText={
<FormattedMessage
id='admin.gitlab.tokenDescription'
defaultMessage='Enter https://<your-gitlab-url>/oauth/token. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
/>
}
placeholder={''}
value={this.state.tokenEndpoint}
onChange={this.handleChange}
disabled={!this.state.enable}
disabled={true}
/>
</SettingsGroup>
);
......
......@@ -82,6 +82,7 @@ export default class OAuthSettings extends AdminSettings {
oauthType,
id: settings.Id,
secret: settings.Secret,
gitLabUrl: config.GitLabSettings.UserApiEndpoint.replace('/api/v4/user', ''),
userApiEndpoint: settings.UserApiEndpoint,
authEndpoint: settings.AuthEndpoint,
tokenEndpoint: settings.TokenEndpoint
......@@ -90,8 +91,10 @@ export default class OAuthSettings extends AdminSettings {
changeType(id, value) {
let settings = {};
let gitLabUrl = '';
if (value === Constants.GITLAB_SERVICE) {
settings = this.config.GitLabSettings;
gitLabUrl = settings.UserApiEndpoint.replace('/api/v4/user', '');
} else if (value === Constants.GOOGLE_SERVICE) {
settings = this.config.GoogleSettings;
} else if (value === Constants.OFFICE365_SERVICE) {
......@@ -101,6 +104,7 @@ export default class OAuthSettings extends AdminSettings {
this.setState({
id: settings.Id,
secret: settings.Secret,
gitLabUrl,
userApiEndpoint: settings.UserApiEndpoint,
authEndpoint: settings.AuthEndpoint,
tokenEndpoint: settings.TokenEndpoint
......@@ -109,6 +113,21 @@ export default class OAuthSettings extends AdminSettings {
this.handleChange(id, value);
}
updateGitLabUrl = (id, value) => {
let trimmedValue = value;
if (value.endsWith('/')) {
trimmedValue = value.slice(0, -1);
}
this.setState({
saveNeeded: true,
gitLabUrl: value,
userApiEndpoint: trimmedValue + '/api/v4/user',
authEndpoint: trimmedValue + '/oauth/authorize',
tokenEndpoint: trimmedValue + '/oauth/token'
});
}
renderTitle() {
return (
<FormattedMessage
......@@ -310,22 +329,34 @@ export default class OAuthSettings extends AdminSettings {
onChange={this.handleChange}
/>
<TextSetting
id='userApiEndpoint'
id='gitlabUrl'
label={
<FormattedMessage
id='admin.gitlab.userTitle'
defaultMessage='User API Endpoint:'
id='admin.gitlab.siteUrl'
defaultMessage='GitLab Site URL:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.userExample', 'Ex "https://<your-gitlab-url>/api/v4/user"')}
placeholder={Utils.localizeMessage('admin.gitlab.siteUrlExample', 'E.g.: https://')}
helpText={
<FormattedMessage
id='admin.gitlab.userDescription'
defaultMessage='Enter https://<your-gitlab-url>/api/v4/user. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
id='admin.gitab.siteUrlDescription'
defaultMessage='Enter the URL of your GitLab instance, e.g. https://example.com:3000. If your GitLab instance is not set up with SSL, start the URL with http:// instead of https://.'
/>
}
value={this.state.gitLabUrl}
onChange={this.updateGitLabUrl}
/>
<TextSetting
id='userApiEndpoint'
label={
<FormattedMessage
id='admin.gitlab.userTitle'
defaultMessage='User API Endpoint:'
/>
}
placeholder={''}
value={this.state.userApiEndpoint}
onChange={this.handleChange}
disabled={true}
/>
<TextSetting
id='authEndpoint'
......@@ -335,15 +366,9 @@ export default class OAuthSettings extends AdminSettings {
defaultMessage='Auth Endpoint:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.authExample', 'Ex "https://<your-gitlab-url>/oauth/authorize"')}
helpText={
<FormattedMessage
id='admin.gitlab.authDescription'
defaultMessage='Enter https://<your-gitlab-url>/oauth/authorize (example https://example.com:3000/oauth/authorize). Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
/>
}
placeholder={''}
value={this.state.authEndpoint}
onChange={this.handleChange}
disabled={true}
/>
<TextSetting
id='tokenEndpoint'
......@@ -353,15 +378,9 @@ export default class OAuthSettings extends AdminSettings {
defaultMessage='Token Endpoint:'
/>
}
placeholder={Utils.localizeMessage('admin.gitlab.tokenExample', 'Ex "https://<your-gitlab-url>/oauth/token"')}
helpText={
<FormattedMessage
id='admin.gitlab.tokenDescription'
defaultMessage='Enter https://<your-gitlab-url>/oauth/token. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.'
/>
}
placeholder={''}
value={this.state.tokenEndpoint}
onChange={this.handleChange}
disabled={true}
/>
</div>
);
......
......@@ -459,8 +459,6 @@
"admin.general.usersAndTeams": "Users and Teams",
"admin.gitlab.clientSecretDescription": "Obtain this value via the instructions above for logging into GitLab.",
"admin.gitlab.EnableHtmlDesc": "<ol><li>Log in to your GitLab account and go to Profile Settings -> Applications.</li><li>Enter Redirect URIs \"<your-mattermost-url>/login/gitlab/complete\" (example: http://localhost:8065/login/gitlab/complete) and \"<your-mattermost-url>/signup/gitlab/complete\". </li><li>Then use \"Application Secret Key\" and \"Application ID\" fields from GitLab to complete the options below.</li><li>Complete the Endpoint URLs below. </li></ol>",
"admin.gitlab.authDescription": "Enter https://<your-gitlab-url>/oauth/authorize (example https://example.com:3000/oauth/authorize). Make sure you use HTTP or HTTPS in your URL depending on your server configuration.",
"admin.gitlab.authExample": "E.g.: \"https://<your-gitlab-url>/oauth/authorize\"",
"admin.gitlab.authTitle": "Auth Endpoint:",
"admin.gitlab.clientIdDescription": "Obtain this value via the instructions above for logging into GitLab",
"admin.gitlab.clientIdExample": "E.g.: \"jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY\"",
......@@ -469,12 +467,11 @@
"admin.gitlab.clientSecretTitle": "Application Secret Key:",
"admin.gitlab.enableDescription": "When true, Mattermost allows team creation and account signup using GitLab OAuth.",
"admin.gitlab.enableTitle": "Enable authentication with GitLab: ",
"admin.gitlab.siteUrl": "GitLab Site URL: ",
"admin.gitlab.siteUrlDescription": "Enter the URL of your GitLab instance, e.g. https://example.com:3000. If your GitLab instance is not set up with SSL, start the URL with http:// instead of https://.",
"admin.gitlab.siteUrlExample": "E.g.: https://",
"admin.gitlab.settingsTitle": "GitLab Settings",
"admin.gitlab.tokenDescription": "Enter https://<your-gitlab-url>/oauth/token. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.",
"admin.gitlab.tokenExample": "E.g.: \"https://<your-gitlab-url>/oauth/token\"",
"admin.gitlab.tokenTitle": "Token Endpoint:",
"admin.gitlab.userDescription": "Enter https://<your-gitlab-url>/api/v4/user. Make sure you use HTTP or HTTPS in your URL depending on your server configuration.",
"admin.gitlab.userExample": "E.g.: \"https://<your-gitlab-url>/api/v4/user\"",
"admin.gitlab.userTitle": "User API Endpoint:",
"admin.google.EnableHtmlDesc": "<ol><li><a target='_blank' href='https://accounts.google.com/login'>Log in</a> to your Google account.</li><li>Go to <a target='_blank' href='https://console.developers.google.com'>https://console.developers.google.com</a>, click <strong>Credentials</strong> in the left hand sidebar and enter \"Mattermost - your-company-name\" as the <strong>Project Name</strong>, then click <strong>Create</strong>.</li><li>Click the <strong>OAuth consent screen</strong> header and enter \"Mattermost\" as the <strong>Product name shown to users</strong>, then click <strong>Save</strong>.</li><li>Under the <strong>Credentials</strong> header, click <strong>Create credentials</strong>, choose <strong>OAuth client ID</strong> and select <strong>Web Application</strong>.</li><li>Under <strong>Restrictions</strong> and <strong>Authorized redirect URIs</strong> enter <strong>your-mattermost-url/signup/google/complete</strong> (example: http://localhost:8065/signup/google/complete). Click <strong>Create</strong>.</li><li>Paste the <strong>Client ID</strong> and <strong>Client Secret</strong> to the fields below, then click <strong>Save</strong>.</li><li>Finally, go to <a target='_blank' href='https://console.developers.google.com/apis/api/plus/overview'>Google+ API</a> and click <strong>Enable</strong>. This might take a few minutes to propagate through Google's systems.</li></ol>",
"admin.google.authTitle": "Auth Endpoint:",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment