File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
oauth/src/connections/jira Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ import axios from 'axios' ;
2+ import { DataObject , OAuthResponse } from '../../lib/types' ;
3+
4+ export const init = async ( { body } : DataObject ) : Promise < OAuthResponse > => {
5+ try {
6+ const {
7+ clientId : client_id ,
8+ clientSecret : client_secret ,
9+ metadata : { code, redirectUri : redirect_uri } ,
10+ } = body ;
11+
12+ const response = await axios ( {
13+ url : 'https://auth.atlassian.com/oauth/token' ,
14+ method : 'POST' ,
15+ params : {
16+ grant_type : 'authorization_code' ,
17+ code,
18+ client_id,
19+ client_secret,
20+ redirect_uri,
21+ } ,
22+ } ) ;
23+
24+ const {
25+ access_token : accessToken ,
26+ refresh_token : refreshToken ,
27+ token_type : tokenType ,
28+ expires_in : expiresIn ,
29+ } = response . data ;
30+
31+ return {
32+ accessToken,
33+ refreshToken,
34+ expiresIn,
35+ tokenType : tokenType === 'bearer' ? 'Bearer' : tokenType ,
36+ meta : { } ,
37+ } ;
38+ } catch ( error ) {
39+ throw new Error ( `Error fetching access token for Jira: ${ error } ` ) ;
40+ }
41+ } ;
Original file line number Diff line number Diff line change 1+ import axios from 'axios' ;
2+ import { DataObject , OAuthResponse } from '../../lib/types' ;
3+
4+ export const refresh = async ( { body } : DataObject ) : Promise < OAuthResponse > => {
5+ try {
6+ const {
7+ OAUTH_CLIENT_ID : client_id ,
8+ OAUTH_CLIENT_SECRET : client_secret ,
9+ OAUTH_REFRESH_TOKEN : refresh_token ,
10+ OAUTH_METADATA : { meta } ,
11+ } = body ;
12+
13+ const response = await axios ( {
14+ url : 'https://auth.atlassian.com/oauth/token' ,
15+ method : 'POST' ,
16+ params : {
17+ grant_type : 'refresh_token' ,
18+ refresh_token,
19+ client_id,
20+ client_secret,
21+ } ,
22+ } ) ;
23+
24+ const {
25+ access_token : accessToken ,
26+ refresh_token : refreshToken ,
27+ token_type : tokenType ,
28+ expires_in : expiresIn ,
29+ } = response . data ;
30+
31+ return {
32+ accessToken,
33+ refreshToken,
34+ expiresIn,
35+ tokenType : tokenType === 'bearer' ? 'Bearer' : tokenType ,
36+ meta,
37+ } ;
38+ } catch ( error ) {
39+ throw new Error ( `Error fetching access token for Jira: ${ error } ` ) ;
40+ }
41+ } ;
You can’t perform that action at this time.
0 commit comments