@@ -161,13 +161,19 @@ def auth(self, username, password):
161161 )
162162 self ._init_resources ()
163163
164- def auth_app (self , app_id , app_secret , auth_code , state = "" ):
164+ def auth_app (self , app_id , auth_code , state ):
165165 """
166- Authenticate an app
166+ Retrieve an application token.
167+ This only works once per token; in order to reset it, the auth code needs
168+ to be set again in the Taiga admin UI.
169+
170+ In order to use the token, initialize TaigaAPI with token_type="Application"
171+ and token="token from this function".
167172
168173 :param app_id: the app id
169- :param app_secret: the app secret
170- :param auth_code: the app auth code
174+ :param auth_code: app auth code as specified in Taiga
175+ :param state: state as specified in Taiga (any string; must not be empty)
176+ :return: token string
171177 """
172178 headers = {"Content-type" : "application/json" }
173179 payload = {"application" : app_id , "auth_code" : auth_code , "state" : state }
@@ -180,31 +186,12 @@ def auth_app(self, app_id, app_secret, auth_code, state=""):
180186 raise exceptions .TaigaRestException (full_url , 400 , "NETWORK ERROR" , "POST" )
181187 if response .status_code != 200 :
182188 raise exceptions .TaigaRestException (full_url , response .status_code , response .text , "POST" )
183- cyphered_token = response .json ().get ("cyphered_token" , "" )
184- if cyphered_token :
185- from jwkest .jwe import JWE
186- from jwkest .jwk import SYMKey
187-
188- sym_key = SYMKey (key = app_secret , alg = "A128KW" )
189- data , success = JWE ().decrypt (cyphered_token , keys = [sym_key ]), True
190- if isinstance (data , tuple ):
191- data , success = data
192- try :
193- self .token = json .loads (data .decode ("utf-8" )).get ("token" , None )
194- except ValueError : # pragma: no cover
195- self .token = None
196- if not success :
197- self .token = None
198- else :
199- self .token = None
200-
201- if self .token is None :
189+ token = response .json ().get ("token" , None )
190+
191+ if token is None :
202192 raise exceptions .TaigaRestException (full_url , 400 , "INVALID TOKEN" , "POST" )
203193
204- self .raw_request = RequestMaker (
205- "/api/v1" , self .host , self .token , "Application" , self .tls_verify , proxies = self .proxies
206- )
207- self ._init_resources ()
194+ return token
208195
209196 def refresh_token (self , token_refresh = "" ):
210197 """
0 commit comments