Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a65ec60
Common code moved to function
ghbm-itk Oct 11, 2023
e8ebe18
Popups for username, password removed
ghbm-itk Oct 11, 2023
c5faf18
Graph Mail implemented
ghbm-itk Oct 18, 2023
322e70d
Merge pull request #13 from itk-dev-rpa/graph
ghbm-itk Oct 18, 2023
18ff9e6
Docstring fix
ghbm-itk Oct 20, 2023
79e1a48
Merge branch 'main' into develop
Krogsager Nov 2, 2023
ab6a832
Merge commit '18ff9e69b1699063dbdc2b135626678b167178ee' into feature/…
Krogsager Nov 7, 2023
57db32b
fix pylint issue "E0601: Using variable 'GraphAccess' before assignme…
Krogsager Nov 2, 2023
ba60962
disable pylint: R0903: Too few public methods (1/2) (too-few-public-m…
Krogsager Nov 2, 2023
43ded55
pylint
Krogsager Nov 6, 2023
59b0214
fix pylint issue "E0601: Using variable 'GraphAccess' before assignme…
Krogsager Nov 2, 2023
c15cbf5
recreate test data.
Krogsager Nov 2, 2023
097a311
recreate test data.
Krogsager Nov 8, 2023
31acfdf
added file
ghbm-itk Nov 10, 2023
5b1c2f4
Minor fixes
ghbm-itk Nov 10, 2023
82ba10a
removed duplicate code
ghbm-itk Nov 10, 2023
8fe82ba
Removed unused main
ghbm-itk Nov 10, 2023
6b8d63f
Merge pull request #17 from itk-dev-rpa/feature/revert_bad_revert
ghbm-itk Nov 10, 2023
5c267d5
Removed disable rules
ghbm-itk Nov 10, 2023
5dce3f2
Lint fix
ghbm-itk Nov 10, 2023
142ef3d
Bunch o fixes
ghbm-itk Nov 10, 2023
a52f51a
Fix
ghbm-itk Nov 10, 2023
b4f6b82
fix
ghbm-itk Nov 10, 2023
3ea4019
fix
ghbm-itk Nov 10, 2023
6be8ca6
Moved test files
ghbm-itk Nov 10, 2023
bbccdb1
fix
ghbm-itk Nov 10, 2023
1ed74d4
Rename folder
ghbm-itk Nov 10, 2023
a72165b
folder name changed
ghbm-itk Nov 10, 2023
5cc55b6
Whitespace
ghbm-itk Nov 10, 2023
8ba639f
Updated tests
ghbm-itk Nov 10, 2023
b56e181
Project name changed
ghbm-itk Nov 10, 2023
2795b51
Fix
ghbm-itk Nov 10, 2023
d7c642c
Module name changed
ghbm-itk Nov 10, 2023
3411fcf
Changed module name
ghbm-itk Nov 10, 2023
6de1121
Updated test
ghbm-itk Nov 10, 2023
0e1534e
Changed function name
ghbm-itk Nov 10, 2023
ff54722
function name changed
ghbm-itk Nov 10, 2023
877c720
Lint fix
ghbm-itk Nov 10, 2023
dfe6ac0
Merge pull request #18 from itk-dev-rpa/fixing-everything
ghbm-itk Nov 14, 2023
830224d
Update python-publish.yml
ghbm-itk Nov 14, 2023
bef5624
Update pyproject.toml
ghbm-itk Nov 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

name: Upload Python Package

on: workflow_dispatch
on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
8 changes: 0 additions & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
[pylint.messages_control]
disable =
C0303, # Trailing whitespace
C0103, # Variable names
C0305, # Trailing newlines
C0304, # Missing final line
C0301, # Line too long
I1101, E1101, # C-modules members
W0621, # Redefine outer name
R0913 # Too many arguments

[MASTER]
ignore-paths = ^tests/ # Ignore the tests folder
119 changes: 0 additions & 119 deletions ITK_dev_shared_components/SAP/sap_login.py

This file was deleted.

71 changes: 0 additions & 71 deletions ITK_dev_shared_components/SAP/tree_util.py

This file was deleted.

63 changes: 63 additions & 0 deletions itk_dev_shared_components/graph/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""This module is responsible for authenticating a Microsoft Graph
connection."""

import msal

# pylint: disable-next=too-few-public-methods
class GraphAccess:
"""An object that handles access to the Graph api.
This object should not be created directly but instead
using one of the authorize methods in the graph.authentication module.
"""
def __init__(self, app: msal.PublicClientApplication, scopes: list[str]) -> str:
self.app = app
self.scopes = scopes

def get_access_token(self):
"""Get the access token to Graph.
This function automatically reuses an existing token
or refreshes an expired one.

Raises:
RuntimeError: If the access token couldn't be acquired.

Returns:
str: The Graph access token.
"""
account = self.app.get_accounts()[0]
token = self.app.acquire_token_silent(self.scopes, account)

if "access_token" in token:
return token['access_token']

if 'error_description' in token:
raise RuntimeError(f"Token could not be acquired. {token['error_description']}")

raise RuntimeError("Something went wrong. No error description was returned from Graph.")


def authorize_by_username_password(username: str, password: str, *, client_id: str, tenant_id: str) -> GraphAccess:
"""Get a bearer token for the given user.
This is used in most other Graph API calls.

Args:
username: The username of the user (email address).
password: The password of the user.
client_id: The Graph API client id in 8-4-4-12 format.
tenant_id: The Graph API tenant id in 8-4-4-12 format.

Returns:
GraphAccess: The GraphAccess object used to authorize Graph access.
"""
authority = f"https://login.microsoftonline.com/{tenant_id}"
scopes = ["https://graph.microsoft.com/.default"]

app = msal.PublicClientApplication(client_id, authority=authority)
app.acquire_token_by_username_password(username, password, scopes)

graph_access = GraphAccess(app, scopes)

# Test connection
graph_access.get_access_token()

return graph_access
Loading