devopshq / teamcity

dohq-teamcity is a Python package providing access to the JetBrains TeamCity server API.
https://devopshq.github.io/teamcity/
MIT License
33 stars 12 forks source link

Quick fix to allow API tokens to be used #29

Closed martwana closed 3 years ago

martwana commented 3 years ago

I've modified this library with minimal changes to support being able to use a TeamCity access token.

I'm not entirely sure why there was some functionality to enable this, but it was not fully implemented.

Usage:

from dohq_teamcity import TeamCity
from dohq_teamcity.configuration import Configuration

config = Configuration()
config.api_key = {'mytoken': 'XXXXXXXXXXXXXXX'}
config.api_key_prefix = {'mytoken': 'Bearer'}
config.active_api_key = 'mytoken'

tc = TeamCity("https://teamcity.example.uk", auth_settings=["Token"], configuration=config)
allburov commented 3 years ago

Nice job! Could you add a little note about this type of authentication in readme?

timka-s commented 3 years ago

After MR broke code: TeamCity("https://teamcity.example.uk", auth=(login, password)) Now raised error HTTP response body: Authentication required

martwana commented 3 years ago

Yeah this was pushed as a quick fix to enable token auth. I did not check username/password login as personally I think its a bad practice to use in scripts.

That authentication method should really be deprecated in favour or other more secure methods.

I've added another commit to hopefully fix that @timka-s on PR https://github.com/devopshq/teamcity/pull/32

Can you give that a test.

cpages commented 3 years ago

Thanks for fixing that. Just a note that your example should read 'auth_settings=["Token"]', not auth. It took me a while to figure out why it was not working for me

martwana commented 3 years ago

Thanks for fixing that. Just a note that your example should read 'auth_settings=["Token"]', not auth. It took me a while to figure out why it was not working for me

Sorted that