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

How to use username and password in REST API? #3560

Closed
lancelodliu opened this issue Aug 28, 2017 · 6 comments
Closed

How to use username and password in REST API? #3560

lancelodliu opened this issue Aug 28, 2017 · 6 comments

Comments

@lancelodliu
Copy link
Contributor

lancelodliu commented Aug 28, 2017

I want to use GET request to http://username:password@127.0.0.1:8010/api/v2/forceschedulers/{schedulername} to get information of the specified scheduler. Is there any reference?
At this time, I got a error message like this:
image

@lancelodliu lancelodliu changed the title How to use UserPasswordAuth in REST API? How to use username and password in REST API? Aug 28, 2017
@lancelodliu
Copy link
Contributor Author

lancelodliu commented Aug 28, 2017

If I set cookies TWISTED_SESSION to a value already got, it is ok. But I need to use REST API in my automated system. Is there a way to achive this like the oauth2 way?

@lancelodliu
Copy link
Contributor Author

Setting auth header doesn't work either.

@lancelodliu
Copy link
Contributor Author

Doc says

Once credentials have been established, a cookie will be set, which must be sent to the buildbot REST API with every request thereafter.

I found it could be done like this.

import requests
import json

data = {
    "jsonrpc": "2.0",
    "method":"force",
    "id":843,
    "params":{
        "p1":1, 
    }
}
url = '127.0.0.1:8010'
s = requests.session()
s.head('http://{}/auth/login'.format(url), auth=('qsmobile', 'qsmobile'), proxies={'http':None})
r = s.post('http://{}/api/v2/forceschedulers/ForceBuild_Scheduler'.format(url), headers={'Content-Type':'application/json'}, data=json.dumps(data), proxies={'http':None})

@Frodox
Copy link
Member

Frodox commented Sep 1, 2017

Could you please add your scheduler and auth-roles from master.cfg?
This definitely should be in docs!

@seankelly please, add #documentation #needs docs labels here :) (just not to miss it, and I want to fix it)

@lancelodliu
Copy link
Contributor Author

lancelodliu commented Sep 1, 2017

@Frodox
master.cfg:

c['www'] = dict(port=8010,
                plugins=dict(
                    waterfall_view=True, 
                    console_view=True),
                allowed_origins=["*"]
                )
c['www']['authz'] = util.Authz(
        allowRules = [
            util.AnyControlEndpointMatcher(role="admins")
        ],
        roleMatchers = [
            util.RolesFromUsername(roles=['admins'], usernames=['qsmobile', 'qsmobile'])
        ]
)
c['www']['auth'] = util.UserPasswordAuth([('qsmobile','qsmobile')])

scheduler:

ForceBuild_Scheduler = ForceScheduler(
    name="ForceBuild_Scheduler",
    label=u"force",
    builderNames=["BuildEntry_Builder"],
    username=util.UserNameParameter(hide=True),
    reason=util.StringParameter(name="reason", default="force build", hide=True),
    codebases=[util.CodebaseParameter(codebase='', hide=True)],
    properties=[util.IntParameter(name="param1",
                                      label=u"param1",
                                      default=1)])

@aj062
Copy link
Contributor

aj062 commented Oct 3, 2019

I faced this as well while trying to figure out how to Authenticate the REST API. Current documentation doesn't explain that well. It would be nice to have the documentation updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants