chainlib

Generic blockchain access library and tooling
Info | Log | Files | Refs | README | LICENSE

auth.py (699B)


      1 # standard imports
      2 import base64
      3 
      4 
      5 class Auth:
      6 
      7     def urllib_header(self):
      8         raise NotImplementedError()
      9 
     10 
     11 class BasicAuth(Auth):
     12 
     13     def __init__(self, username, password):
     14         self.username = username
     15         self.password = password
     16 
     17 
     18     def urllib_header(self):
     19         s = '{}:{}'.format(self.username, self.password)
     20         b = base64.b64encode(s.encode('utf-8'))
     21         return (('Authorization'), ('Basic ' + b.decode('utf-8')),)
     22 
     23 
     24 class CustomHeaderTokenAuth(Auth):
     25 
     26     def __init__(self, header_name, auth_token):
     27         self.header_name = header_name
     28         self.auth_token = auth_token
     29 
     30 
     31     def urllib_header(self):
     32         return (self.header_name, self.auth_token,)