Skip to content

Commit 04dee52

Browse files
committed
fix(oauth): rename user_info to userinfo and fix example attribute access
- Rename user_info method to userinfo in OAuthClient and AsyncOAuthClient - Replace dict-style .get() calls with dataclass attribute access in examples - Update test method names and calls to match the renamed method
1 parent 234b29b commit 04dee52

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

examples/01_user_login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def main() -> None:
2929

3030
# Use the client to call an OAuth endpoint (e.g., UserInfo).
3131
userinfo = client.userinfo(token.access_token)
32-
print(f"Subject : {userinfo.get('sub')}")
33-
print(f"Email : {userinfo.get('email')}")
32+
print(f"Subject : {userinfo.sub}")
33+
print(f"Email : {userinfo.email}")
3434

3535

3636
if __name__ == "__main__":

examples/04_async_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def main() -> None:
2828
print(f"Logged in! access_token={token.access_token[:20]}...")
2929

3030
userinfo = await client.userinfo(token.access_token)
31-
print(f"Subject: {userinfo.get('sub')}")
31+
print(f"Subject: {userinfo.sub}")
3232

3333

3434
if __name__ == "__main__":

src/authgate/oauth/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def introspect(self, token: str) -> IntrospectionResult:
156156
jti=body.get("jti", ""),
157157
)
158158

159-
async def user_info(self, access_token: str) -> UserInfo:
159+
async def userinfo(self, access_token: str) -> UserInfo:
160160
"""Fetch user information from the UserInfo endpoint (OIDC Core 1.0 SS5.3)."""
161161
if not self._endpoints.userinfo_url:
162162
raise OAuthError("invalid_request", "userinfo endpoint not configured")

src/authgate/oauth/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def introspect(self, token: str) -> IntrospectionResult:
156156
jti=body.get("jti", ""),
157157
)
158158

159-
def user_info(self, access_token: str) -> UserInfo:
159+
def userinfo(self, access_token: str) -> UserInfo:
160160
"""Fetch user information from the UserInfo endpoint (OIDC Core 1.0 SS5.3)."""
161161
if not self._endpoints.userinfo_url:
162162
raise OAuthError("invalid_request", "userinfo endpoint not configured")

tests/test_oauth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def handler(request: httpx.Request) -> httpx.Response:
159159
assert result.active
160160
assert result.scope == "openid profile"
161161

162-
def test_user_info(self, endpoints: Endpoints) -> None:
162+
def test_userinfo(self, endpoints: Endpoints) -> None:
163163
def handler(request: httpx.Request) -> httpx.Response:
164164
assert "Bearer" in request.headers["Authorization"]
165165
return httpx.Response(
@@ -177,7 +177,7 @@ def handler(request: httpx.Request) -> httpx.Response:
177177
endpoints,
178178
http_client=httpx.Client(transport=transport),
179179
)
180-
info = client.user_info("access-token")
180+
info = client.userinfo("access-token")
181181
assert info.sub == "user123"
182182
assert info.name == "Test User"
183183

@@ -232,7 +232,7 @@ def test_missing_endpoint_raises(self) -> None:
232232
with pytest.raises(OAuthError, match="introspection endpoint"):
233233
client.introspect("tok")
234234
with pytest.raises(OAuthError, match="userinfo endpoint"):
235-
client.user_info("tok")
235+
client.userinfo("tok")
236236
with pytest.raises(OAuthError, match="tokeninfo endpoint"):
237237
client.token_info_request("tok")
238238

0 commit comments

Comments
 (0)