Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Authorization Code Flow Helper. Learn more about auth-code-flow at https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow
Async based OAuth using the Microsoft Authentication Library (MSAL) for Python.
Blocking MSAL functions are executed in the executor thread. Should be useful until such time as MSAL Python gets a true async version.
Tested with MSAL Python 1.21.0 onward - MSAL Python docs
The AsyncMSAL class wraps the behavior in the following example app https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/app.py#L76
It is responsible to manage tokens & token refreshes and as a client to retrieve data using these tokens.
Firstly you should get the tokens via OAuth
initiate_auth_code_flow
referernce
The caller is expected to:
Step 1 and part of Step 3 is stored by this class in the aiohttp_session
acquire_token_by_auth_code_flow
referernce
Now you are free to make requests (typically from an aiohttp server)
session = await get_session(request)
aiomsal = AsyncMSAL(session)
async with aiomsal.get("https://graph.microsoft.com/v1.0/me") as res:
res = await res.json()
Complete routes can be found in routes.py
@ROUTES.get("/user/login")
async def user_login(request: web.Request) -> web.Response:
"""Redirect to MS login page."""
session = await new_session(request)
redir = AsyncMSAL(session).build_auth_code_flow(
redirect_uri=get_route(request, URI_USER_AUTHORIZED)
)
return web.HTTPFound(redir)
@ROUTES.post(URI_USER_AUTHORIZED)
async def user_authorized(request: web.Request) -> web.Response:
"""Complete the auth code flow."""
session = await get_session(request)
auth_response = dict(await request.post())
aiomsal = AsyncMSAL(session)
await aiomsal.async_acquire_token_by_auth_code_flow(auth_response)
@ROUTES.get("/user/photo")
Serve the user's photo from their Microsoft profile
get_user_info
Get the user's email and display name from MS Graph
get_manager_info
Get the user's manager info from MS Graph
from aiohttp_msal import ENV, AsyncMSAL
from aiohttp_msal.redis_tools import get_session
def main()
# Uses the redis.asyncio driver to retrieve the current token
# Will update the token_cache if a RefreshToken was used
ases = asyncio.run(get_session(MYEMAIL))
client = GraphClient(ases.get_token)
# ...
# use the Graphclient
FAQs
Helper Library to use the Microsoft Authentication Library (MSAL) with aiohttp
We found that aiohttp-msal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.