pymsteams
pymsteams copied to clipboard
HttpPost Basic Auth.
Hi, I don't know if it's possible. I could not find anything about this in Microsoft Docs either. It is about "HttpPost". Is there also the possibility for an authentication there, similar to "requests" with basic auth. via "auth=("user", "pw")?
Thanks in advance!
It appears that the API does not accept explicit basic auth parameters, but it does accept headers. https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication where the header value is a base64 encoded username/password combo.
The functionality to accept a username and password, encode and autoformat could be added onto pymsteams. It's not currently on the roadmap, but I'd be willing to review and merge a pull request.
Hi, thanks for the answer!
def addAction(self,_type,_name,_target): if "actions" not in self.payload.keys(): self.payload["actions"] = [] action = { "@type": _type, "name": _name, "target": _target }
Maybe we have to add the following to the action dict:
headers = { "Authorization": "Basic {}".format( b64encode(bytes(f"{user}:{password}", "utf-8")).decode("ascii") )
Do you think that will work? If yes, I can try to implement this and I'll do a pull request.
I think that could work. If it does, please submit!
On Wed, Sep 22, 2021 at 9:18 AM svenrr @.***> wrote:
Hi, thanks for the answer!
def addAction(self,_type,_name,_target): if "actions" not in self.payload.keys(): self.payload["actions"] = [] action = { @.***": _type, "name": _name, "target": _target }
Maybe we have to add the following to the action dict:
headers = { "Authorization": "Basic {}".format( b64encode(bytes(f"{user}:{password}", "utf-8")).decode("ascii") )
Do you think that will work? If yes, I can try to implement this and I'll do a pull request.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rveachkc/pymsteams/issues/107#issuecomment-924976360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXLSLPOJSEFYIFGRFUZJFDUDHQTFANCNFSM5D5PWCMQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Hi, I came up with the following (see addAction): https://github.com/svenrr/pymsteams/blob/master/pymsteams/init.py
The payload seems to work but I got this teams error:
The remote endpoint has returned an error (HTTP Unauthorized). Please try again later.
it looks like this:
'actions': [{'@type': 'HttpPost', 'name': 'Claim', 'target': 'www.xxx.com/task/claim', 'headers': [{'name': 'Authorization', 'value': 'Basic Y2FtYWRtaw32ZEV8J28sLkEuLnrVu3diT147JzA='}], 'body': 'userId=admin', 'bodyContentType': 'application/x-www-form-urlencoded'}
Maybe you have an idea?
Hmmm....seems as if that should work. I'm assuming the button appeared as you expected, then you saw the error when the button was clicked?
Perhaps the header doesn't work as expected? Is this something you can get working outside of teams, maybe with curl?
On Thu, Sep 23, 2021 at 5:30 AM svenrr @.***> wrote:
Hi, I came up with the following (see addAction): https://github.com/svenrr/pymsteams/blob/master/pymsteams/init.py
The payload seems to work but I got this teams error: The remote endpoint has returned an error (HTTP Unauthorized). Please try again later.
it looks like this: 'actions': @.***': 'HttpPost', 'name': 'Claim', 'target': ' www.xxx.com/task/claim', 'headers': [{'name': 'Authorization', 'value': 'Basic Y2FtYWRtaw32ZEV8J28sLkEuLnrVu3diT147JzA='}], 'body': 'userId=admin', 'bodyContentType': 'application/x-www-form-urlencoded'}
Maybe you have an idea?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rveachkc/pymsteams/issues/107#issuecomment-925689709, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXLSLNOSF2RIJMSSLZIEJ3UDL6TRANCNFSM5D5PWCMQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
yes exactly. Do you know if there is any logging or where I can find more information about the error?
I tried to do the same with requests module and there it worked, but there are small differences. You don't put the auth json in an array/list and normally you put the data/variables not in the header...
for body I also tried json/dict in a string. But as I mentioned, pretty hard to find the solution without any error log.