-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathapp.py
55 lines (44 loc) · 1.7 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import json
import random
import time
import requests
from walkoff_app_sdk.app_base import AppBase
class MicrosoftSecurity(AppBase):
__version__ = "1.0.0"
app_name = "oauth2-example"
def __init__(self, redis, logger, console_logger=None):
"""
Each app should have this __init__ to set up Redis and logging.
:param redis:
:param logger:
:param console_logger:
"""
super().__init__(redis, logger, console_logger)
def authenticate(self, access_token, refresh_token):
s = requests.Session()
s.headers = {
"Content-Type": "application/json",
"Authorization": "Bearer %s" % access_token
}
return s
# UserAuthenticationMethod.ReadWrite.All
def reset_password(self, access_token, refresh_token, userId, passwordId, newPassword=""):
graph_url = "https://graph.microsoft.com"
session = self.authenticate(access_token, refresh_token)
url = "https://graph.microsoft.com/beta/users/%s/authentication/methods/%s/resetPassword" % (userId, passwordId)
response = session.post(url)
print(response.status_code)
return response.text
# UserAuthenticationMethod.ReadWrite.All
def get_password_methods(self, access_token, refresh_token):
graph_url = "https://graph.microsoft.com"
session = self.authenticate(access_token, refresh_token)
url = "https://graph.microsoft.com/beta/me/authentication/passwordMethods"
response = session.get(url)
print(response.status_code)
return response.text
if __name__ == "__main__":
MicrosoftSecurity.run()