Skip to content

Commit

Permalink
Added support for domainCredentials for authenticating to EventGrid d…
Browse files Browse the repository at this point in the history
…omains. (#160)
  • Loading branch information
kalyanaj authored and lmazuel committed Jun 12, 2019
1 parent f7c91dd commit 7ad6a11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion msrest/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,22 @@ def __init__(self, topic_key):
self._topic_key_header: topic_key,
}
)


class DomainCredentials(ApiKeyCredentials):
"""Event Grid domain authentication.
:param str domain_key: The Event Grid domain key
"""

_domain_key_header = 'aeg-sas-key'

def __init__(self, domain_key):
# type: (str) -> None
if not domain_key:
raise ValueError("Domain key cannot be None")
super(DomainCredentials, self).__init__(
in_headers={
self._domain_key_header: domain_key,
}
)

9 changes: 8 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
OAuthTokenAuthentication,
ApiKeyCredentials,
CognitiveServicesCredentials,
TopicCredentials
TopicCredentials,
DomainCredentials
)

from requests import Request, PreparedRequest
Expand Down Expand Up @@ -133,6 +134,12 @@ def test_eventgrid_auth(self):
prep_req = session.prepare_request(self.request)
self.assertDictContainsSubset({'aeg-sas-key' : 'mytopickey'}, prep_req.headers)

def test_eventgrid_domain_auth(self):
auth = DomainCredentials("mydomainkey")
session = auth.signed_session()
prep_req = session.prepare_request(self.request)
self.assertDictContainsSubset({'aeg-sas-key' : 'mydomainkey'}, prep_req.headers)

if __name__ == '__main__':
unittest.main()

0 comments on commit 7ad6a11

Please sign in to comment.