Ejemplo n.º 1
0
def authenticate_for_test(userid, userpwd):
    '''Use basic authentication against Reva for testing purposes'''
    authReq = cs3gw.AuthenticateRequest(type='basic',
                                        client_id=userid,
                                        client_secret=userpwd)
    authRes = ctx['cs3stub'].Authenticate(authReq)
    ctx['log'].debug('msg="Authenticated user" res="%s"' % authRes)
    if authRes.status.code != cs3code.CODE_OK:
        raise IOError('Failed to authenticate as user ' + userid + ': ' +
                      authRes.status.message)
    return authRes.token
Ejemplo n.º 2
0
    def _auth_in_iop(self, client_secret_or_token, login_type="basic"):

        auth_req = cs3gw.AuthenticateRequest(
            type=login_type,
            client_id=self.config['client_id'],
            client_secret=client_secret_or_token)
        auth_res = self.cs3_stub.Authenticate(auth_req)

        if auth_res.status.code != cs3code.CODE_OK or self._check_token(
                auth_res.token) is False:
            self.raise_401_error()

        return auth_res.token
Ejemplo n.º 3
0
def init(inconfig, inlog):
  '''Init module-level variables'''
  global config         # pylint: disable=global-statement
  global log            # pylint: disable=global-statement
  global tok            # pylint: disable=global-statement
  config = inconfig
  log = inlog
  #revaurl = config.get('cs3', 'revaurl')
  revaurl = 'iota:19000' # XXX for now

  # prepare the gRPC connection
  ch = grpc.insecure_channel(revaurl)
  cs3stub = cs3gw_grpc.GatewayAPIStub(ch)
  authReq = cs3gw.AuthenticateRequest(type='basic', client_id='gonzalhu', client_secret='test')
  tok = cs3stub.Authenticate(authReq)
Ejemplo n.º 4
0
    def authenticate(self, client_id):
        # ToDo: use real authentication data or get token from author provider
        # authReq = cs3gw.AuthenticateRequest(type='bearer', client_secret=userid)

        if client_id not in self.tokens or self.tokens[client_id]['exp'] < time.time():
            auth_req = cs3gw.AuthenticateRequest(type=self.config['login_type'],
                                                 client_id=self.config['client_id'],
                                                 client_secret=self.config['client_secret'])
            auth_res = self.cs3_api.Authenticate(auth_req)
            self.tokens[client_id] = {'tok': auth_res.token,
                                    'exp': time.time() + float(self.config['auth_token_validity'])}

        # piggy back on the opportunity to expire old tokens, but asynchronously
        # as to not impact the current session: let's use python3.7's coroutines support
        # asyncio.run(_async_cleanuptokens())

        return self.tokens[client_id]['tok']