File tree 6 files changed +62
-2
lines changed
6 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,22 @@ const client = new Client({
111
111
});
112
112
```
113
113
114
+ ### OAuth1.0 authentication
115
+
116
+ ``` js
117
+ const client = new Client ({
118
+ host: " https://jira.somehost.com" ,
119
+ authentication: {
120
+ oauth1: {
121
+ consumerKey: " your consumer key" ,
122
+ consumerSecret: " -----BEGIN RSA PRIVATE KEY-----\n " + " some private key\n " + " -----END RSA PRIVATE KEY-----" ,
123
+ accessToken: " your access token" ,
124
+ tokenSecret: " your token secret"
125
+ }
126
+ }
127
+ });
128
+ ```
129
+
114
130
### OAuth2.0 authentication
115
131
116
132
``` js
Original file line number Diff line number Diff line change 29
29
"@types/express" : " ^4.17.8" ,
30
30
"@types/jest" : " ^26.0.15" ,
31
31
"@types/node" : " ^14.14.5" ,
32
+ "@types/oauth" : " ^0.9.1" ,
32
33
"@types/sinon" : " ^9.0.8" ,
33
34
"@typescript-eslint/eslint-plugin" : " ^4.6.0" ,
34
35
"@typescript-eslint/parser" : " ^4.6.0" ,
44
45
},
45
46
"dependencies" : {
46
47
"atlassian-jwt" : " ^1.0.3" ,
47
- "axios" : " ^0.21.0"
48
+ "axios" : " ^0.21.0" ,
49
+ "oauth" : " ^0.9.15"
48
50
}
49
51
}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export namespace Config {
17
17
jwt ?: Authentication . JWT ;
18
18
accessToken ?: Authentication . AccessToken ;
19
19
basic ?: Authentication . Basic ;
20
+ oauth1 ?: Authentication . OAuth1 ;
20
21
}
21
22
22
23
export interface Middlewares {
@@ -42,6 +43,13 @@ export namespace Config {
42
43
password ?: string ;
43
44
} ;
44
45
46
+ export type OAuth1 = {
47
+ consumerKey : string ;
48
+ consumerSecret : string ;
49
+ accessToken : string ;
50
+ tokenSecret : string ;
51
+ } ;
52
+
45
53
export type AccessToken = string ;
46
54
}
47
55
}
Original file line number Diff line number Diff line change 1
1
import { AxiosRequestConfig } from 'axios' ;
2
2
import * as jwt from 'atlassian-jwt' ;
3
3
import * as url from 'url' ;
4
+ import { OAuth } from 'oauth' ;
4
5
import { Config } from '../config' ;
5
6
6
7
export const getAuthentication = (
@@ -30,6 +31,26 @@ export const getAuthentication = (
30
31
return `JWT ${ jwtToken } ` ;
31
32
}
32
33
34
+ if ( config . authentication ?. oauth1 ) {
35
+ const oauthUrl = `${ config . host } /plugins/servlet/oauth/` ;
36
+ const oauth = new OAuth (
37
+ `${ oauthUrl } request-token` ,
38
+ `${ oauthUrl } access-token` ,
39
+ config . authentication . oauth1 . consumerKey ,
40
+ config . authentication . oauth1 . consumerSecret ,
41
+ '1.0' ,
42
+ null ,
43
+ 'RSA-SHA1' ,
44
+ ) ;
45
+
46
+ return oauth . authHeader (
47
+ url . resolve ( config . host , request . url ! ) ,
48
+ config . authentication . oauth1 . accessToken ,
49
+ config . authentication . oauth1 . tokenSecret ,
50
+ request . method ! ,
51
+ ) ;
52
+ }
53
+
33
54
if ( config . authentication ?. accessToken ) {
34
55
return `Bearer ${ config . authentication . accessToken } ` ;
35
56
}
Original file line number Diff line number Diff line change @@ -293,7 +293,8 @@ export class Client {
293
293
public async sendRequest ( request : AxiosRequestConfig , callback ?: Callback ) : Promise < any > {
294
294
try {
295
295
request . headers = Utils . removeUndefinedElements ( {
296
- Authorization : getAuthentication ( this . config , request ) ,
296
+ Authorization : getAuthentication ( this . config ,
297
+ { ...request , url : this . requestInstance . getUri ( request ) } ) ,
297
298
...request . headers ,
298
299
} ) ;
299
300
Original file line number Diff line number Diff line change 667
667
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz"
668
668
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==
669
669
670
+ " @types/oauth@^0.9.1 " :
671
+ version "0.9.1"
672
+ resolved "https://registry.yarnpkg.com/@types/oauth/-/oauth-0.9.1.tgz#e17221e7f7936b0459ae7d006255dff61adca305"
673
+ integrity sha512-a1iY62/a3yhZ7qH7cNUsxoI3U/0Fe9+RnuFrpTKr+0WVOzbKlSLojShCKe20aOD1Sppv+i8Zlq0pLDuTJnwS4A==
674
+ dependencies :
675
+ " @types/node" " *"
676
+
670
677
" @types/prettier@^2.0.0 " :
671
678
version "2.1.1"
672
679
resolved "https://registry.npmjs.org/@types/prettier/-/prettier-2.1.1.tgz"
@@ -3467,6 +3474,11 @@ oauth-sign@~0.9.0:
3467
3474
resolved "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz"
3468
3475
integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
3469
3476
3477
+ oauth@^0.9.15 :
3478
+ version "0.9.15"
3479
+ resolved "https://registry.yarnpkg.com/oauth/-/oauth-0.9.15.tgz#bd1fefaf686c96b75475aed5196412ff60cfb9c1"
3480
+ integrity sha1-vR/vr2hslrdUda7VGWQS/2DPucE=
3481
+
3470
3482
object-copy@^0.1.0 :
3471
3483
version "0.1.0"
3472
3484
resolved "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz"
You can’t perform that action at this time.
0 commit comments