Skip to content

Commit

Permalink
WORK-263 #8 add setup support for custom oauth provider (gitlab based)
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Sep 3, 2015
1 parent f732ed9 commit 0fedc05
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/webapp/setup/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
$rootScope.persona = {audience: $window.location.protocol + '//' + $window.location.hostname + ':' + getPort($window)};
$rootScope.oauth = {baseUrl: getOrigin($window) + $window.location.pathname.replace(/setup\/$/, '')};
$rootScope.oauthProviders = ['bitbucket', 'gitlab', 'github', 'google', 'twitter'];
$rootScope.oauthCustomizable = ['gitlab'];
$rootScope.oauthNewProvider = {};
angular.forEach($rootScope.oauthProviders, function (p) {
$rootScope.oauth[p] = {present: false};
});
Expand Down Expand Up @@ -185,6 +187,21 @@
addProviderIfPresent(newOauthConf.providers, $scope.oauth['github'], 'github') && loginType.push('oauth.github');
addProviderIfPresent(newOauthConf.providers, $scope.oauth['google'], 'google') && loginType.push('oauth.google');
addProviderIfPresent(newOauthConf.providers, $scope.oauth['twitter'], 'twitter') && loginType.push('oauth.twitter');

if($scope.oauthNewProvider.type) {
var providerName = $scope.oauthNewProvider.type+'-'+$scope.oauthNewProvider.name;
newOauthConf.providers.push({
provider: providerName,
apiKey: $scope.oauthNewProvider.apiKey,
apiSecret: $scope.oauthNewProvider.apiSecret,
hasCustomBaseAndProfileUrl: true,
baseProvider: $scope.oauthNewProvider.type,
baseUrl: $scope.oauthNewProvider.baseUrl
});

loginType.push('oauth.'+providerName);
}

config.push({first: 'OAUTH_CONFIGURATION', second: JSON.stringify(newOauthConf)});
$rootScope.selectedNewOauthConf = newOauthConf;
} else if ($scope.authMethod == 'DEMO') {
Expand Down
39 changes: 38 additions & 1 deletion src/main/webapp/setup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ <h4>Check ldap configuration</h4>
<div class="checkbox">
<label class="capitalize"><input type="checkbox"
data-ng-model="oauth[provider].present"
data-ng-required="countSelectedOauth() == 0"> {{provider}}</label>
data-ng-required="countSelectedOauth() == 0 && oauthNewProvider.type == null"> {{provider}}</label>
</div>
<div data-ng-if="oauth[provider].present">
<div class="form-group">
Expand All @@ -227,6 +227,42 @@ <h4>Check ldap configuration</h4>
</div>
</li>
</ul>
<div class="or"><hr><span>Or</span></div>
<div>Custom OAuth provider:</div>
<div>
<div class="form-group">
<label for="oauthNewProvider.type">Type</label>
<select class="form-control" data-ng-model="oauthNewProvider.type" id="oauthNewProvider.type" ng-required data-ng-options="name for name in oauthCustomizable">
<option></option>
</select>
</div>
<div class="form-group">
<label for="oauthNewProvider.name">Name</label>
<input class="form-control" type="text" data-ng-model="oauthNewProvider.name" id="oauthNewProvider.name" ng-required="oauthNewProvider.type.length > 0" pattern="[a-z]*" maxlength="10">
</div>
<div class="form-group">
<label for="oauthNewProvider.baseUrl">Base url</label>
<input class="form-control" type="text" data-ng-model="oauthNewProvider.baseUrl" id="oauthNewProvider.baseUrl" ng-required="oauthNewProvider.type.length > 0">
</div>
<!--
<div class="form-group">
<label for="oauthNewProvider.profileUrl">Profile url</label>
<input class="form-control" type="text" data-ng-model="oauthNewProvider.profileUrl" id="oauthNewProvider.profileUrl">
</div>
-->
<div class="form-group">
<label for="oauthNewProvider.apiKey">Api Key</label>
<input class="form-control" type="text" data-ng-model="oauthNewProvider.apiKey" id="oauthNewProvider.apiKey" ng-required="oauthNewProvider.type.length > 0">
</div>
<div class="form-group">
<label for="oauthNewProvider.apiSecret">Api Secret</label>
<input class="form-control" type="text" data-ng-model="oauthNewProvider.apiSecret" id="oauthNewProvider.apiSecret" ng-required="oauthNewProvider.type.length > 0">
</div>
<div class="form-group">
<label for="oauthNewProvider.callback">Callback url is:</label>
<input id="oauthNewProvider.callback" class="form-control form-selectable" type="text" disabled value="{{oauth.baseUrl}}login/oauth/{{oauthNewProvider.type}}-{{oauthNewProvider.name}}/callback">
</div>
</div>
</div>
</div>
<div class="buttons">
Expand Down Expand Up @@ -284,6 +320,7 @@ <h4>Check ldap configuration</h4>
<li>Base url: {{selectedNewOauthConf.baseUrl}}</li>
<li data-ng-repeat="v in selectedNewOauthConf.providers" style="margin-top:10px;">
<div>Provider: {{v.provider}}</div>
<div ng-if="v.hasCustomBaseAndProfileUrl">Base url for custom provider: {{v.baseUrl}}</div>
<div>Api Key: {{v.apiKey}}</div>
<div>Api Secret: {{v.apiSecret}}</div>
</li>
Expand Down

0 comments on commit 0fedc05

Please sign in to comment.