How to authenticate with REST API
Make sure these boxes are checked before submitting your issue - thank you!
- [x] I have checked the superset logs for python stacktraces and included it here as text if any
- [x] I have reproduced the issue with at least the latest released version of superset
- [x] I have checked the issue tracker for the same issue and I haven't found one similar
Superset version
0.17.1
Expected results
N/A
Actual results
N/A
Steps to reproduce
Sorry if this has been answered somewhere else, but is there any documentation on how to authenticate through the REST API?
Specifically, I'd like to be able to return JSON from the /superset/explore_json/ endpoint (copied from the UI slice view) using cURL (or something similar) but I get the following response when I do:
{
"message": "Access is Denied",
"severity": "danger"
}
Thanks
This is how we do it in the unit tests: https://github.com/airbnb/superset/blob/master/tests/base_tests.py#L127
But that may vary depending on the type of authentication you use.
Hey @amancevice did you figure this out? I have this exact use case and was wondering if you solve it. Thanks!
@slarrain I did not -- gave up & moved on to other things. Sorry!
For those still looking for some kind of solution - the following example seems to work:
import requests
from bs4 import BeautifulSoup
# set up session for auth
s = requests.Session()
login_form = s.post("http://my_server/login")
# get Cross-Site Request Forgery protection token
soup = BeautifulSoup(login_form.text, 'html.parser')
csrf_token = soup.find('input',{'id':'csrf_token'})['value']
# login the given session
s.post('http://my_server/login/',data=dict(username='admin', password='my_passwd',csrf_token=csrf_token))
# run API call
print(s.get('http://my_server/users/api').text)
Is there a documentation of the rest api ?
The part we get for free on modelviews through FAB is documented here: https://github.com/dpgaspar/Flask-AppBuilder/blob/master/docs/quickhowto.rst#exposed-methods
i need authentication by using json web tokens
For those still looking for some kind of solution - the following example seems to work:
import requests from bs4 import BeautifulSoup # set up session for auth s = requests.Session() login_form = s.post("http://my_server/login") # get Cross-Site Request Forgery protection token soup = BeautifulSoup(login_form.text, 'html.parser') csrf_token = soup.find('input',{'id':'csrf_token'})['value'] # login the given session s.post('http://my_server/login/',data=dict(username='admin', password='my_passwd',csrf_token=csrf_token)) # run API call print(s.get('http://my_server/users/api').text)
I had to change login_form = s.post("http://my_server/login") to login_form = s.get("http://my_server/login") for this to work. thanks!
The solution to the problem is pretty simple. Just hit post api "api/v1/security/login". Provide the JSON body with following { "password": "complex-password", "provider": "db", "refresh": true, "username": "admin" } The jwt token will be generated in the response.
Hi pritypriya25 its working for me.it generated jwt token. how can i need to fetch dashboard in superset through /dashboard/ endpoint can you please help me. Thank you
@imanju you can check superset api . It provides APIs for all kind of operations. https://superset.apache.org/docs/rest-api It also has a swagger ui where you can check for all APIs.
The solution to the problem is pretty simple. Just hit post api "api/v1/security/login". Provide the JSON body with following { "password": "complex-password", "provider": "db", "refresh": true, "username": "admin" } The jwt token will be generated in the response.
This can be used with default authentication. But I'm using a custom Security Manager to login and I don't have a password for the superset user (since it uses an external OAuth2 provider). How can I login to the APIs?
I have similar problem like @cyanoboy. I am also using a custom Security Manager(external OAuth2 provider). Couldn't find a way to get the JWT token to query the APIs.
I do see that the request body has a provider field:
{
"password": "complex-password",
"provider": "db",
"refresh": true,
"username": "admin"
}
However, cannot find the right provider to use for the custom Security Manager. What to use when there is no username/password style db authentication.?
Any help is highly appreciated. Thanks in advance!
I have the same issue and am wondering if it's just more straight forward to get the token from the oath provider directly and use it within superset. It should work. I"m going to give it a try and see if it works.
I haven't really found a good way to authenticate non password based accounts against the rest api. So far only db and ldap work. What I have resorted to is creating a db based "service account" and using that for api actions
@nytai can this db based service account work if use auth_type as AUTH_Oauth. I assume the bearer token will be from the issuer signed rs256 token how can this be used with api in superset
Faced this problem trying to access explore_json with JWT token. This doesn't work cause this endpoint is missing @protected decorator. Want to make a PR to fix it (or receive feedback why I shouldn't do so).
hello , i want to integrate superset with an external existing service , but the problem is that users have to login twice (one for the service and one for supsetset ) can i bypass it with the jwt token ?
did anyone face this before ?
@SAVE-POlNT we are doing exact this thing now. But, of course, there are some pitfalls and also it depends on existing service. I don't think this topic matches this issue but you can contact me directly so we could discuss your problem.
@xneg i would like to , can yu please leave your discord or your e-mail so i can contact you ?