Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
support for Basic authentication of Kong admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
miso-m committed Jun 12, 2019
1 parent 7ecba96 commit e142ce3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
14 changes: 13 additions & 1 deletion api/models/KongNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var defaultModel = _.merge(_.cloneDeep(require('../base/Model')), {

type: {
type: 'string',
enum: ['default', 'key_auth', 'jwt'],
enum: ['default', 'key_auth', 'jwt', 'basic_auth'],
defaultsTo: 'default'
},

Expand Down Expand Up @@ -65,6 +65,18 @@ var defaultModel = _.merge(_.cloneDeep(require('../base/Model')), {
type: 'string'
},

/**
* Basic auth
*/
username: {
type: 'string',
defaultsTo: ''
},
password: {
type: 'string',
defaultsTo: ''
},

kong_version: {
type: 'string',
required: true,
Expand Down
4 changes: 4 additions & 0 deletions api/services/KongService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var KongService = {
var token = JWT.issueKongConnectionToken(connection);
headers.Authorization = "Bearer " + token;
break;
case "basic_auth":
var basicAuthtoken = Buffer.from(connection.username + ":" + connection.password).toString('base64');
headers.Authorization = "Basic " + basicAuthtoken;
break;
}

return headers;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/app/connections/edit-connection-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$scope.node = _node;

$scope.active = ['default','key_auth','jwt'].indexOf($scope.node.type);
$scope.active = ['default','key_auth','jwt','basic_auth'].indexOf($scope.node.type);

$scope.close = function(){
$uibModalInstance.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@
</div>

</uib-tab>

<uib-tab index="3" ng-click="node.type='basic_auth'">
<uib-tab-heading>
Basic AUTH
</uib-tab-heading>
<br>
<div class="alert alert-info text-small">
Konga will connect to Kong's admin using Basic authentication. configured in nginx.<br>
</div>
</uib-tab>
</uib-tabset>
<br>
<div class="form-group" ng-class="{'has-error' : errors.name}">
Expand Down Expand Up @@ -81,7 +89,18 @@
<div class="text-danger" ng-if="errors.jwt_secret" data-ng-bind="errors.jwt_secret"></div>
</div>
</div>

<div ng-switch-when="basic_auth">
<div class="form-group" ng-class="{'has-error' : errors.username}">
<label class="control-label">Username <span class="text-danger">*</span></label>
<input ng-model="node.username" ng-required="node.type=='basic_auth'" class="form-control" placeholder="The `Username` ...">
<div class="text-danger" ng-if="errors.username" data-ng-bind="errors.username"></div>
</div>
<div class="form-group" ng-class="{'has-error' : errors.password}">
<label class="control-label">Password <span class="text-danger">*</span></label>
<input ng-model="node.password" ng-required="node.type=='basic_auth'" class="form-control" placeholder="The Basic Authentication Password" type="password">
<div class="text-danger" ng-if="errors.password" data-ng-bind="errors.password"></div>
</div>
</div>
</div>


Expand Down
24 changes: 22 additions & 2 deletions assets/js/app/connections/partials/create-connection-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<a href="https://getkong.org/docs/latest/secure-admin-api/#kong-api-loopback" target="_blank">Check out how to setup a JWT based "loop-back" API</a>.
</div>
</uib-tab>
<uib-tab index="3" ng-click="node.type='basic_auth'">
<uib-tab-heading>
Basic AUTH
</uib-tab-heading>
<br>
<div class="alert alert-info text-small">
Konga will connect to Kong's admin using Basic authentication.<br>
</div>
</uib-tab>
</uib-tabset>
<div class="col-md-12">
<div class="form-group" ng-class="{'has-error' : errors.name}">
Expand All @@ -43,7 +52,7 @@
</div>
<div class="form-group" ng-class="{'has-error' : errors.kong_admin_url}">
<label class="control-label">
{{node.type == 'default' ? 'Kong Admin' : 'Loopback API'}} URL
{{(node.type == 'default' || node.type == 'basic_auth')? 'Kong Admin' : 'Loopback API'}} URL
<span class="text-danger">*</span></label>
<input type="url" ng-model="node.kong_admin_url" class="form-control" placeholder="The URL to Kong's {{node.type == 'default' ? 'admin' : 'Loopback'}} API" required="required">
<div class="text-danger" ng-if="errors.kong_admin_url" data-ng-bind="errors.kong_admin_url"></div>
Expand Down Expand Up @@ -78,7 +87,18 @@
<div class="text-danger" ng-if="errors.jwt_secret" data-ng-bind="errors.jwt_secret"></div>
</div>
</div>

<div ng-switch-when="basic_auth">
<div class="form-group" ng-class="{'has-error' : errors.username}">
<label class="control-label">Username <span class="text-danger">*</span></label>
<input ng-model="node.username" ng-required="node.type=='basic_auth'" class="form-control" placeholder="The Basic Authentication Username">
<div class="text-danger" ng-if="errors.username" data-ng-bind="errors.username"></div>
</div>
<div class="form-group" ng-class="{'has-error' : errors.password}">
<label class="control-label">Password <span class="text-danger">*</span></label>
<input ng-model="node.password" ng-required="node.type=='basic_auth'" class="form-control" placeholder="The Basic Authentication Password" type="password">
<div class="text-danger" ng-if="errors.password" data-ng-bind="errors.password"></div>
</div>
</div>
</div>


Expand Down

0 comments on commit e142ce3

Please sign in to comment.