@@ -160,24 +160,32 @@ def _resolve_credential(self, credential):
160160 credential = credential , profile = self .profile
161161 )
162162
163- def fetch_tokens (self , code = None , redirect_uri = None ):
163+ def fetch_tokens (self , client_id = None , client_secret = None , code = None ,
164+ redirect_uri = None ):
164165 """Fetch tokens from token URL.
165166
166167 Args:
168+ client_id (str): OAuth2 client ID. Defaults to ``None``.
169+ client_secret (str): OAuth2 client secret. Defaults to ``None``.
167170 code (str): Authorization code. Defaults to ``None``.
168171 redirect_uri (str): Redirect URI. Defaults to ``None``.
169172
170173 Returns:
171174 dict: Response from token URL.
172175
173176 """
177+ client_id = client_id or self .client_id
178+ client_secret = client_secret or self .client_secret
174179 redirect_uri = redirect_uri or self .redirect_uri
175- c = self .get_credentials ()
176180 r = requests .post (
177181 self .token_url ,
182+ headers = {
183+ 'Content-Type' : 'application/x-www-form-urlencoded'
184+ },
178185 data = {
179- 'client_id' : c .client_id ,
180- 'client_secret' : c .client_secret ,
186+ 'grant_type' : 'authorization_code' ,
187+ 'client_id' : client_id ,
188+ 'client_secret' : client_secret ,
181189 'code' : code ,
182190 'redirect_uri' : redirect_uri
183191 },
@@ -202,11 +210,13 @@ def fetch_tokens(self, code=None, redirect_uri=None):
202210 raise PanCloudError (r .text )
203211 return r .json ()
204212
205- def get_authorization_url (self , instance_id = None , redirect_uri = None ,
206- region = None , scope = None , state = None ):
213+ def get_authorization_url (self , client_id = None , instance_id = None ,
214+ redirect_uri = None , region = None , scope = None ,
215+ state = None ):
207216 """Generate authorization URL.
208217
209218 Args:
219+ client_id (str): OAuth2 client ID. Defaults to ``None``.
210220 instance_id (str): App Instance ID. Defaults to ``None``.
211221 redirect_uri (str): Redirect URI. Defaults to ``None``.
212222 region (str): App Region. Defaults to ``None``.
@@ -217,17 +227,17 @@ def get_authorization_url(self, instance_id=None, redirect_uri=None,
217227 str, str: Auth URL, state
218228
219229 """
230+ client_id = client_id or self .client_id
220231 instance_id = instance_id or self .instance_id
221232 redirect_uri = redirect_uri or self .redirect_uri
222233 region = region or self .region
223234 scope = scope or self .scope
224235 state = state or self .state
225- c = self .get_credentials ()
226236 return requests .Request (
227237 'GET' ,
228238 self .auth_base_url ,
229239 params = {
230- 'client_id' : c . client_id ,
240+ 'client_id' : client_id ,
231241 'instance_id' : instance_id ,
232242 'redirect_uri' : redirect_uri ,
233243 'region' : region ,
0 commit comments