Giter Site home page Giter Site logo

httpie-ems-auth's Introduction

httpie-ems-auth

This HTTPie auth plugin implements Escher authentication for Emarsys API requests.

Installation

HTTPie is a Python package, you need Python 2.7.* to be installed on your computer first. Be sure that HTTPie is installed (version 0.9.6, higher versions crash), and install this plugin.

MacOS specific installation

Important: do not install HTTPie via Brew.

To install python 2 before installing httpie-ems-auth, run brew install python.

pip install httpie==0.9.6
pip install httpie-ems-auth

Ubuntu 16.04 specific installation

In order to work around some Ubuntu specific errors, httpie and httpie-ems-auth has to be installed for the current user only.

pip install --user httpie==0.9.6
pip install --user httpie-ems-auth

This installs the http binary to the directory ~/.local/bin. It is recommended to add this directory to the current user's path by adding $HOME/.local/bin to the PATH (ie. by modifying ~/.profile: change the PATH="$HOME/bin:$PATH" to PATH="$HOME/bin:$HOME/.local/bin:$PATH".)

Verification

After installation, execute http --help | grep ems-auth.

Success criteria: the command returns lines containing ems-auth.

Example

Suiteable if you call the API of Suite

http --auth-type=ems-auth --auth=escher_key:escher_secret https://api.emarsys.net/api/v2/internal/12345678/settings

The default Escher credential scope is "eu/suite/ems_request" which identifies Suite. If u are calling another service, you have to alter the credential scope like this:

http --auth-type=ems-auth --auth=eu/suite/ems_request/escher_key:escher_secret https://api.emarsys.net/api/v2/internal/12345678/settings

Check out HTTPie sessions, if you would like to save authentication information between your requests.

If you want to use in python code this example can help:

      import escherauth
      import datetime
      from urlparse import urlparse
      import requests
      
      escher_key = 'test'
      escher_secret = 'test'
      options = {
                  'algo_prefix': 'EMS',
                  'vendor_key': 'EMS',
                  'hash_algo': 'SHA256',
                  'auth_header_name': 'X-Ems-Auth',
                  'date_header_name': 'X-Ems-Date'
                }
      
      credential_scope = "test"
      
      if "/" in escher_key:
          scope = escher_key.split("/")
          escher_key = scope.pop()
          credential_scope = "/".join(scope)
      
      client = {'api_key': escher_key, 'api_secret': escher_secret}
      escher = escherauth.Escher(credential_scope, options)
      
      url = 'http://test-escher-url.com/api/call/smth'
      
      r = requests.PreparedRequest()
      r.prepare('GET',url)
      now = datetime.datetime.utcnow()
      r.headers['X-Ems-Date'] = now.strftime('%Y%m%dT%H%M%SZ')
      parsed_uri = urlparse(r.url)
      r.headers['Host'] = parsed_uri.netloc
      
      f = escher.sign(r, client)
      s = requests.Session()
      
      s.send(f)

httpie-ems-auth's People

Contributors

boogie avatar sonicoder86 avatar gopitzer avatar szenti avatar

Stargazers

 avatar Sergey Korsik avatar ferencs jamrik avatar Phil Davies avatar Hristo Ganev avatar Balint Soos avatar Jakub Roztocil avatar

Watchers

Simon Csaba Péter avatar Viktor Somodi avatar András Fincza avatar  avatar James Cloos avatar Daniel Szpisjak avatar Adam Pinter avatar  avatar Ferenc Kalcso avatar  avatar  avatar Krizsán Balázs avatar  avatar  avatar

httpie-ems-auth's Issues

Throws error with httpie 0.9.7+

Installing HTTPie version 0.9.7 or higher breaks the request.

Traceback (most recent call last):
  File "/usr/local/bin/http", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/httpie/__main__.py", line 11, in main
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/httpie/core.py", line 210, in main
    parsed_args = parser.parse_args(args=args, env=env)
  File "/usr/local/lib/python2.7/site-packages/httpie/input.py", line 168, in parse_args
    self._process_auth()
  File "/usr/local/lib/python2.7/site-packages/httpie/input.py", line 268, in _process_auth
    password=credentials.value,
TypeError: get_auth() got an unexpected keyword argument 'username'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.