Last active
April 12, 2018 12:22
-
-
Save kartoch/8891061 to your computer and use it in GitHub Desktop.
Revisions
-
kartoch revised this gist
Nov 21, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ users fill the hubic authentication form with its navigator and obtain the credentials returned by the application. You need requests-oauthlib and flask: pip install flask pip install requests-oauthlib The client and id secret are valid but users can create their own application -
kartoch revised this gist
Nov 21, 2014 . 1 changed file with 43 additions and 66 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,81 +1,58 @@ """ As Hubic web services are deprecated, this is a small script to request access and refresh token. It starts a flask server at http://localhost:5000/, the users fill the hubic authentication form with its navigator and obtain the credentials returned by the application. You need requests-oauthlib to works: pip install requests-oauthlib The client and id secret are valid but users can create their own application on hubic and change the values of these entries. """ from requests_oauthlib import OAuth2Session from flask import Flask, request, redirect, session, url_for from flask.json import jsonify import os import uuid; os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' app = Flask(__name__) client_id = 'api_hubic_dMCUY8MLynmkpIgdrj2D8GlbaSPemHAE' client_secret = '9TgfdUFvjTCXgOahwz0ai1kEh03RrvDKI0kw4kZ3hCCbC2pQPtvJSdcKlTyFz3Q6' authorization_base_url = 'https://api.hubic.com/oauth/auth/?' token_url = 'https://api.hubic.com/oauth/token/' redirect_uri = "http://localhost:5000/callback" scope = u"usage.r,account.r,getAllLinks.r,credentials.r,activate.w,links.drw" state = 'RandomString_' + str(uuid.uuid4().get_hex().upper()[0:10]) @app.route("/") def start(): hubic = OAuth2Session(client_id, scope=scope, state=state, redirect_uri=redirect_uri) authorization_url, state_back = hubic.authorization_url(authorization_base_url) return redirect(authorization_url) @app.route("/callback", methods=["GET"]) def callback(): hubic = OAuth2Session(client_id, state=state,redirect_uri=redirect_uri) token = hubic.fetch_token(token_url, client_secret=client_secret, authorization_response=request.url) session['oauth_token'] = token return redirect(url_for('.account')) @app.route("/account", methods=["GET"]) def account(): hubic = OAuth2Session(client_id, token=session['oauth_token']) return jsonify(session['oauth_token']) if __name__ == "__main__": app.secret_key = os.urandom(24) app.run(debug=True) -
kartoch created this gist
Feb 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ #!/usr/bin/env python2 import base64 import json import logging import requests import sys from swiftclient import client class AuthenticationHubic: def __init__(self, user, passwd): self.logger = logging.getLogger(__name__) self.SessionHandler = 'https://ws.ovh.com/sessionHandler/r4/' self.hubicws = 'https://ws.ovh.com/hubic/r5/' r = requests.get(self.SessionHandler + 'rest.dispatcher/' + 'getAnonymousSession') sessionId = r.json()['answer']['session']['id'] self.logger.info("sessionId:" + sessionId) params = { 'sessionId': sessionId, 'email': user} payload = {'params': json.dumps(params)} r = requests.get(self.hubicws + 'rest.dispatcher/' + 'getHubics', params=payload) hubics = r.json() self.hubicsId = hubics['answer'][0]['id'] self.logger.info("hubicsId:" + self.hubicsId) params = { 'login': hubics['answer'][0]['nic'], 'password': passwd, 'context': 'hubic'} payload = {'params': json.dumps(params)} r = requests.get(self.SessionHandler + 'rest.dispatcher/' + 'login', params=payload) self.sessionId = r.json()['answer']['session']['id'] self.logger.info("authenticated hubicsId:" + self.sessionId) def get_credentials(self): params = { 'sessionId': self.sessionId, 'hubicId': self.hubicsId} payload = {'params': json.dumps(params)} r = requests.get(self.hubicws + 'rest.dispatcher/' + 'getHubic', params=payload) Storage_Url = base64.b64decode(r.json()['answer']['credentials']['username']) self.logger.info("storage url:" + str(Storage_Url)) Auth_Token = r.json()['answer']['credentials']['secret'] self.logger.info("auth token:" + Auth_Token) return Storage_Url, Auth_Token def logout(self): params = { 'sessionId': self.sessionId} payload = {'params': json.dumps(params)} r = requests.get(self.SessionHandler + 'rest.dispatcher/' + 'logout', params=payload) if __name__ == '__main__': logging.basicConfig(level = logging.ERROR) if len(sys.argv) != 3: logging.error("Usage: sys.argv[0] login password") sys.exit(1) login = sys.argv[1] passwd = sys.argv[2] auth = AuthenticationHubic(login, passwd) storage_url, auth_token = auth.get_credentials() print("export SWIFT_PREAUTHURL=\"" + str(storage_url) +"\";" ) print("export SWIFT_PREAUTHTOKEN=\"" + auth_token + "\"") auth.logout()