diff --git a/docs/api/api.md b/docs/api/api.md index 73e28a1cad..a9db423f35 100644 --- a/docs/api/api.md +++ b/docs/api/api.md @@ -97,72 +97,6 @@ There are JWT libraries available for most languages as highlighted on [jwt.io]( `Authorization: Bearer eyJhb[...omitted for brevity...]HgQ` -### Python Example -Here is an example of how to create a token as Python client: - -```python -import jwt -import datetime -import hashlib - -method = 'GET' -uri = '/volumes' -secret = 'My secret' - -claims = {} - -# Issuer -claims['iss'] = 'admin' - -# Issued at time -claims['iat'] = datetime.datetime.utcnow() - -# Expiration time -claims['exp'] = datetime.datetime.utcnow() \ - + datetime.timedelta(minutes=10) - -# URI tampering protection -claims['qsh'] = hashlib.sha256(method + '&' + uri).hexdigest() - -print jwt.encode(claims, secret, algorithm='HS256') -``` - -Example output: - -``` -eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhZG1pbiIsImlhdCI6MTQzNTY4MTY4OSwicXNoIjoiYzE2MmFjYzkwMjQyNzIxMjBiYWNmZmY3NzA5YzkzMmNjMjUyMzM3ZDBhMzBmYTE1YjAyNTAxMDA2NjY2MmJlYSIsImV4cCI6MTQzNTY4MjI4OX0.ZBd_NgzEoGckcnyY4_ypgJsN6Oi7x0KxX2w8AXVyiS8 -``` - -### Ruby Example -Run this as: `./heketi-api.rb volumes` - -```ruby -#!/usr/bin/env ruby - -require 'jwt' -require 'digest' - -user = "admin" -pass = "password" -server = "http://heketi.example.com:8443" - -uri = "/#{ARGV[0]}" - -payload = {} - -headers = { - iss: 'admin', - iat: Time.now.to_i, - exp: Time.now.to_i + 600, - qsh: Digest::SHA256.hexdigest("GET&#{uri}") -} - -token = JWT.encode headers, pass, 'HS256' - -exec("curl -H \"Authorization: Bearer #{token}\" #{server}#{uri}") -``` - -Copy this example token and decode it in [jwt.io](http://jwt.io) by pasting it in the token area and changing the secret to `My secret`. ## More Information * [JWT Specification](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html)