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

Unable to use App Tokens in REST API #59

Open
cla-azzarello opened this issue Apr 30, 2024 · 2 comments
Open

Unable to use App Tokens in REST API #59

cla-azzarello opened this issue Apr 30, 2024 · 2 comments

Comments

@cla-azzarello
Copy link

cla-azzarello commented Apr 30, 2024

Hi,

I generated an app token, but I cannot use it.

I use it with:
curl -v -X GET http://<my_server-Ip>api/v1/certificates -H 'Authorization: Token <MY_TOKEN>'

and also in python:

r = requests.get('http://<my_server-Ip>/api/v1/certificates?format=json',
                 headers={'Authorization': 'Token <MY_TOKEN>'})
print(r)
print(r.text)

but I always have a

<Response [401]>
{"detail":"Invalid token."}

If I use the token from my logged in browser session I have a good response.

What I'm missing?

I cannot found the API documentation.

Thanks.

@scrill
Copy link

scrill commented May 15, 2024

Hi, you need to login to get the token. Here is the Ruby example:

#!/usr/bin/env ruby

require 'json'
require 'net/http'

uri = URI.parse('http://localhost:8080')
http = Net::HTTP.new(uri.host, uri.port)

headers = { 'Content-Type' => 'application/json' }
data = { username: 'admin', password: 'admin' }.to_json
response = http.post('/api/v1/auth/login/', data, headers)
token = JSON.parse(response.body)['key']

headers = {
  'Authorization' => "Token #{token}",
  'Content-Type' => 'application/json'
}
response = http.get('/api/v1/certificates', headers)
pp JSON.parse(response.body)

@cla-azzarello
Copy link
Author

Yes, I know I can use the username/password login to bounca.

Then what is the purpose of the function of generating an auth token?

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