Skip to content

Instantly share code, notes, and snippets.

@herrersystem
Last active October 4, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrersystem/fbeea3c026fe225104edd9866dea2bac to your computer and use it in GitHub Desktop.
Save herrersystem/fbeea3c026fe225104edd9866dea2bac to your computer and use it in GitHub Desktop.
Freebox OS API - Login and logout to API
#!/usr/bin/env python
import hmac
from apize.apize import Apize
app = Apize('http://mafreebox.freebox.fr/api/v3')
@app.call('/login/session/', method='POST')
def connect_app(app_token, app_id, challenge):
h = hmac.new(app_token.encode(), challenge, 'sha1')
password = h.hexdigest()
data = {'app_id': app_id, 'password': password}
headers = {'X-Fbx-App-Auth': app_token}
return {
'data': data,
'headers': headers,
'is_json': True
}
@app.call('/login/authorize/:id')
def authorize_app(track_id):
args = {'id': track_id}
return {'args': args}
@apize(api_url + '/login/logout/', method='POST')
def deconnect_app(session_token):
headers = {'X-Fbx-App-Auth': session_token}
return {'headers': headers}
def get_session_token(app_token, app_id, track_id):
response = authorize_app(track_id)
challenge = response['data']['result']['challenge'].encode()
conn = connect_app(app_token, app_id, challenge)
session_token = conn['data']['result']['session_token']
#For more infos on app return all conn object, example:
#print(conn['data']['result']['permissions'])
return session_token
if __name__ == '__main__':
'''
For get app_token, app_id and track_id see:
https://gist.github.com/herrersystem/eb0d3cef9c51d34e1b09ae47ab611c40
For more information, see official doc:
http://dev.freebox.fr/sdk/os/login/
'''
app_token = '<app_token>'
app_id = '<app_id>'
track_id = 0
session_token = get_session_token(app_token, app_id, track_id)
if session_token:
#Call API functions ...
deconnect_app(session_token)
@herrersystem
Copy link
Author

Pas de prise en charge des erreurs (remontées par l'API) pour simplifier le code.

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