0

I'm able to authenticate against some RESTful API with one of the following methods:

  • password
  • certificate
  • anonymous

I've created AuthenticationBase class and its subclassess:

  • PasswordAuthentication
  • CertificateAuthentication
  • AnonymousAuthentication

Basically authentication take two steps:

  1. get_rsts_token
  2. set_access_token - You need RSTS token first

set_access_token has the same implementation across subclasses but get_rsts_token differs so I've tried something like this:

import abc

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})

class AuthenticationBase(ABC):

    @abc.abstractmethod
    def get_rsts_token(self):
        pass

    def set_access_token()
       rsts_token = self.get_rsts_token()
       access_token = retrieve_token(rsts_token)

but it leads to an error:

TypeError: Can't instantiate abstract class AuthenticationBase with abstract methods get_rsts_token

I wish to avoid rewriting set_access_token in all subclasses. How to achieve this?

user3719188
  • 590
  • 5
  • 7
  • This code doesn't produce the error you're talking about. Please post a [mcve]. – ForceBru Feb 09 '19 at 21:37
  • You don't have to; you just have to provide a definition of `get_rsts_token`, because that error gets raised before you ever try to run `set_access_token`. – chepner Feb 09 '19 at 21:40
  • @ForceBru: I've checked once again and You're right. But how to enforce in set_access_token() method that I want to invoke get_rsts_token() from subclass and not self.get_rsts_token() – user3719188 Feb 09 '19 at 22:34

0 Answers0