diff options
author | Phong Pham <pt2pham@users.noreply.github.com> | 2019-03-22 21:24:29 -0400 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2019-03-22 18:24:29 -0700 |
commit | 8e2ed3ebb45f98e71b7c77fdd52472b815bb7ad2 (patch) | |
tree | 3e01a6011767468010734d603bcfdf4c64f7afa5 /kafka/oauth/abstract.py | |
parent | d032844ad945b6e99845c40cfe08e026a56d332a (diff) | |
download | kafka-python-8e2ed3ebb45f98e71b7c77fdd52472b815bb7ad2.tar.gz |
Support SASL OAuthBearer Authentication (#1750)
Diffstat (limited to 'kafka/oauth/abstract.py')
-rw-r--r-- | kafka/oauth/abstract.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/kafka/oauth/abstract.py b/kafka/oauth/abstract.py new file mode 100644 index 0000000..8d89ff5 --- /dev/null +++ b/kafka/oauth/abstract.py @@ -0,0 +1,42 @@ +from __future__ import absolute_import + +import abc + +# This statement is compatible with both Python 2.7 & 3+ +ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()}) + +class AbstractTokenProvider(ABC): + """ + A Token Provider must be used for the SASL OAuthBearer protocol. + + The implementation should ensure token reuse so that multiple + calls at connect time do not create multiple tokens. The implementation + should also periodically refresh the token in order to guarantee + that each call returns an unexpired token. A timeout error should + be returned after a short period of inactivity so that the + broker can log debugging info and retry. + + Token Providers MUST implement the token() method + """ + + def __init__(self, **config): + pass + + @abc.abstractmethod + def token(self): + """ + Returns a (str) ID/Access Token to be sent to the Kafka + client. + """ + pass + + def extensions(self): + """ + This is an OPTIONAL method that may be implemented. + + Returns a map of key-value pairs that can + be sent with the SASL/OAUTHBEARER initial client request. If + not implemented, the values are ignored. This feature is only available + in Kafka >= 2.1.0. + """ + return {} |