@@ -20,14 +20,12 @@ export class TokenClient {
20
20
exchangeCode ( args = { } ) {
21
21
args = Object . assign ( { } , args ) ;
22
22
23
- var basicAuth = undefined ;
24
- var urlQuery = "" ;
25
-
26
23
args . grant_type = args . grant_type || "authorization_code" ;
27
24
args . client_id = args . client_id || this . _settings . client_id ;
28
25
args . client_secret = args . client_secret || this . _settings . client_secret ;
29
26
args . redirect_uri = args . redirect_uri || this . _settings . redirect_uri ;
30
27
28
+ var basicAuth = undefined ;
31
29
var client_authentication = args . _client_authentication || this . _settings . _client_authentication ;
32
30
delete args . _client_authentication ;
33
31
@@ -52,21 +50,17 @@ export class TokenClient {
52
50
return Promise . reject ( new Error ( "A client_secret is required" ) ) ;
53
51
}
54
52
55
-
56
53
// Sending the client credentials using the Basic Auth method
57
54
if ( client_authentication == "client_secret_basic" )
58
55
{
59
56
basicAuth = args . client_id + ':' + args . client_secret ;
60
- urlQuery = "?grant_type=" + encodeURIComponent ( args . grant_type ) +
61
- "&redirect_uri=" + encodeURIComponent ( args . redirect_uri ) +
62
- "&code=" + encodeURIComponent ( args . code ) ;
63
-
64
- args = { } ;
57
+ delete args . client_id ;
58
+ delete args . client_secret ;
65
59
}
66
60
67
61
return this . _metadataService . getTokenEndpoint ( false ) . then ( url => {
68
62
Log . debug ( "TokenClient.exchangeCode: Received token endpoint" ) ;
69
- return this . _jsonService . postForm ( url + urlQuery , args , basicAuth ) . then ( response => {
63
+ return this . _jsonService . postForm ( url , args , basicAuth ) . then ( response => {
70
64
Log . debug ( "TokenClient.exchangeCode: response received" ) ;
71
65
return response ;
72
66
} ) ;
@@ -80,6 +74,10 @@ export class TokenClient {
80
74
args . client_id = args . client_id || this . _settings . client_id ;
81
75
args . client_secret = args . client_secret || this . _settings . client_secret ;
82
76
77
+ var basicAuth = undefined ;
78
+ var client_authentication = args . _client_authentication || this . _settings . _client_authentication ;
79
+ delete args . _client_authentication ;
80
+
83
81
if ( ! args . refresh_token ) {
84
82
Log . error ( "TokenClient.exchangeRefreshToken: No refresh_token passed" ) ;
85
83
return Promise . reject ( new Error ( "A refresh_token is required" ) ) ;
@@ -89,10 +87,18 @@ export class TokenClient {
89
87
return Promise . reject ( new Error ( "A client_id is required" ) ) ;
90
88
}
91
89
90
+ // Sending the client credentials using the Basic Auth method
91
+ if ( client_authentication == "client_secret_basic" )
92
+ {
93
+ basicAuth = args . client_id + ':' + args . client_secret ;
94
+ delete args . client_id ;
95
+ delete args . client_secret ;
96
+ }
97
+
92
98
return this . _metadataService . getTokenEndpoint ( false ) . then ( url => {
93
99
Log . debug ( "TokenClient.exchangeRefreshToken: Received token endpoint" ) ;
94
100
95
- return this . _jsonService . postForm ( url , args ) . then ( response => {
101
+ return this . _jsonService . postForm ( url , args , basicAuth ) . then ( response => {
96
102
Log . debug ( "TokenClient.exchangeRefreshToken: response received" ) ;
97
103
return response ;
98
104
} ) ;
0 commit comments