Skip to content

Commit d7cf43f

Browse files
committed
Adds support for authenticating via OAuth access token
1 parent 2ec8e6f commit d7cf43f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: lib/gitlab.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ module.exports = Gitlab;
2727
* @param {Object} options
2828
* - {String} api, api root url, e.g.: 'http://gitlab.com/api/v3'
2929
* - {String} privateToken, You can find or reset your private token in your profile.
30+
* - {String} accessToken, Obtained via OAuth
3031
*/
3132
function Gitlab(options) {
3233
options = options || {};
3334
options.api = options.api || 'https://gitlab.com/api/v3';
3435
RESTFulClient.call(this, options);
3536
this.privateToken = options.privateToken;
37+
this.accessToken = options.accessToken;
3638

3739
this.addResources(resources);
3840

@@ -45,7 +47,12 @@ function Gitlab(options) {
4547
util.inherits(Gitlab, RESTFulClient);
4648

4749
Gitlab.prototype.setAuthentication = function (req) {
48-
req.params.data.private_token = req.params.data.private_token || this.privateToken;
50+
var accessToken = req.params.data.access_token || this.accessToken;
51+
if (accessToken) {
52+
req.params.data.access_token = accessToken;
53+
} else {
54+
req.params.data.private_token = req.params.data.private_token || this.privateToken;
55+
}
4956
return req;
5057
};
5158

0 commit comments

Comments
 (0)