Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpPost Basic Auth. #107

Open
svenrr opened this issue Sep 13, 2021 · 6 comments
Open

HttpPost Basic Auth. #107

svenrr opened this issue Sep 13, 2021 · 6 comments

Comments

@svenrr
Copy link

svenrr commented Sep 13, 2021

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!

@rveachkc
Copy link
Owner

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.

@svenrr
Copy link
Author

svenrr commented Sep 22, 2021

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.

@rveachkc
Copy link
Owner

rveachkc commented Sep 22, 2021 via email

@svenrr
Copy link
Author

svenrr commented Sep 23, 2021

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?

@rveachkc
Copy link
Owner

rveachkc commented Sep 23, 2021 via email

@svenrr
Copy link
Author

svenrr commented Sep 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants