Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion fastapi_sso/sso/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class OpenID(pydantic.BaseModel):
display_name: Optional[str] = None
picture: Optional[str] = None
provider: Optional[str] = None

roles: Optional[list[str]] = None

class SecurityWarning(UserWarning):
"""Raised when insecure usage is detected"""
Expand Down
9 changes: 8 additions & 1 deletion fastapi_sso/sso/microsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pydantic

from fastapi_sso.sso.base import DiscoveryDocument, OpenID, SSOBase
from fastapi_sso.sso.base import DiscoveryDocument, OpenID, SSOBase, _decode_id_token
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make _decode_id_token public if we need it elsewhere 👌


if TYPE_CHECKING:
import httpx # pragma: no cover
Expand Down Expand Up @@ -45,12 +45,19 @@ async def get_discovery_document(self) -> DiscoveryDocument:
"userinfo_endpoint": f"https://graph.microsoft.com/{self.version}/me",
}

async def get_user_roles(self) -> list[str]:
"""Get user roles from Microsoft ID token."""
token_info = _decode_id_token(self._id_token)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_id_token may be None, please doublecheck the failed workflows

return token_info.get("roles")

async def openid_from_response(self, response: dict, session: Optional["httpx.AsyncClient"] = None) -> OpenID:
token_info = _decode_id_token(self._id_token)
return OpenID(
email=response.get("mail"),
display_name=response.get("displayName"),
provider=self.provider,
id=response.get("id"),
first_name=response.get("givenName"),
last_name=response.get("surname"),
roles=token_info.get("roles"),
)
Loading