Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiTokenAuthentication #82

Closed
Jonatha1983 opened this issue May 15, 2019 · 17 comments
Closed

ApiTokenAuthentication #82

Jonatha1983 opened this issue May 15, 2019 · 17 comments
Milestone

Comments

@Jonatha1983
Copy link

Hi @mkobit

First thing THANKS!!!! You are a genius!!!

I searched on some docs on how to create: ApiTokenAuthentication

(* I am new to Kotlin )

Thanks ahead !!!

@mkobit
Copy link
Owner

mkobit commented May 15, 2019

@Jonatha1983 good call, there is definitely a gap in the documentation around it. I'll try to add some documentation today.

Could you elaborate on what you are trying to accomplish?

@Jonatha1983
Copy link
Author

We are trying to be able to use the same versions of dependencies used by our Jenknis.
I tried something like:
authentication.set(providers.provider{ BasicAuthentication("user", "pass") })
baseUrl.set(uri("ourJenknisURL").toURL())

and ran retrieveJenkinsPluginData but got 403 Forbidden with user anonymous

@Jonatha1983
Copy link
Author

by the way: retrieveJenkinsVersion working perfectly!!

@mkobit
Copy link
Owner

mkobit commented May 16, 2019

If I remember right, you should be able to replace

authentication.set(providers.provider{ BasicAuthentication("user", "pass") })

with

authentication.set(providers.provider{ ApiTokenAuthentication("user", "apiTokenTextOrReadFromFileOSomewhereElse") })

I'm going to add a few tests to verify that that works, but you might not have the appropriate permissions to access them from the Jenkins server. I think you need to have like admin or something type privileges for it, but I'll figure it out some point soon.

@mkobit
Copy link
Owner

mkobit commented May 16, 2019

I might be wrong on that also - see https://support.cloudbees.com/hc/en-us/articles/218756317-How-can-non-admin-users-view-the-installed-plugins-

I'll do some investigation

@Jonatha1983
Copy link
Author

I imported your project with include build (Composit Build) to debug it - and I found:

  1. BasicAuthentication and ApiTokenAuthentication are implemented exactly the same way.
  2. Also in both the headers are construct with the word "Authentication" when I changed it to "Authorization" for the ApiTokenAuthentication it works for me. ( found it here: https://www.baeldung.com/guide-to-okhttp )

what do you think ?

Also I wanted to ask if today the gradle file take in consideration the plugin versions or it just for human validation ?

Thanks again !!

@mkobit
Copy link
Owner

mkobit commented May 20, 2019

BasicAuthentication and ApiTokenAuthentication are implemented exactly the same way.

I think I did that by design, because the same headers were sent - it is tough to remember and I don't have an integration test against a @JenkinsRule that sets that up to verify that is the case. I'm hoping to get that done sometime this week.

Also I wanted to ask if today the gradle file take in consideration the plugin versions or it just for human validation ?

If I am interpreting your question right, the plugins provided to the build script are used in compilation of the src and vars code (not strict compilation, more of a quick check to verify syntax correctness since Jenkins operates on source code) and are used at runtime in integrationTest to be loaded in the @JenkinsRule so you can accurately test your shared library against expected Jenkins versions.

@Jonatha1983
Copy link
Author

Thanks @mkobit !

And about the Authentication vs Authorization ? would you want me to create a pull request with the change ?

@mkobit
Copy link
Owner

mkobit commented May 20, 2019

@Jonatha1983 ahh, I think I now understand what you are saying. The headers for ApiTokenAuthentication should be Authorization, not Authentication? If so, then yes, would definitely accept an MR for that.

I would to add an additional test that tests those headers against an actual Jenkins instance, but if you don't have time to do that don't worry about it, I can do that part of on my own.

@mkobit
Copy link
Owner

mkobit commented May 20, 2019

Ok so I went and took a quick look

curl localhost:5050/pluginManager/api/json --user admin:11fe35abb2dbfcfc819979ed454bdd06d6

Works for me when I was using a local project, but then trying out the same pattern with ApiTokenAuthentication it wasn't working 😕 .

So, probably a bug somewhere in this plugin

I'll look at it more tonight this week.

@mkobit
Copy link
Owner

mkobit commented May 21, 2019

Thanks @mkobit !

And about the Authentication vs Authorization ? would you want me to create a pull request with the change ?

That is definitely the issue

@Jonatha1983
Copy link
Author

I am about to push if it is ok the tests i ll push later on this week - since I need to learn more the code ...

@mkobit
Copy link
Owner

mkobit commented May 21, 2019

Sounds good @Jonatha1983 , open it whenever you are ready - whatever you have I'll take and get it in, and try and release a new version with the fixes.

I think I'll postpone writing tests against an actual Jenkins in this project since it requires a bit of test infrastructure I don't have yet.

@Jonatha1983
Copy link
Author

@mkobit I think you need to gather me permissions

@mkobit
Copy link
Owner

mkobit commented May 21, 2019

@Jonatha1983 would you mind forking and opening a pull request?

@mkobit mkobit added this to the 0.9.0 milestone May 21, 2019
@Jonatha1983
Copy link
Author

Sure , i ll read how to do it and do it today on.... thanks

mkobit added a commit that referenced this issue May 22, 2019
@mkobit
Copy link
Owner

mkobit commented May 23, 2019

Will be released as 0.9.0 as soon as I figure out #81

If I don't figure it out by Friday will manually release it instead of relying on Circle CI automation

Closing

@mkobit mkobit closed this as completed May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants