Include provider type in auth token response (#72560)

This commit is contained in:
Paulus Schoutsen 2022-05-27 10:31:48 -07:00 committed by GitHub
parent d59258bd25
commit a733b92389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -19,13 +19,15 @@ Exchange the authorization code retrieved from the login flow for tokens.
Return value will be the access and refresh tokens. The access token will have Return value will be the access and refresh tokens. The access token will have
a limited expiration. New access tokens can be requested using the refresh a limited expiration. New access tokens can be requested using the refresh
token. token. The value ha_auth_provider will contain the auth provider type that was
used to authorize the refresh token.
{ {
"access_token": "ABCDEFGH", "access_token": "ABCDEFGH",
"expires_in": 1800, "expires_in": 1800,
"refresh_token": "IJKLMNOPQRST", "refresh_token": "IJKLMNOPQRST",
"token_type": "Bearer" "token_type": "Bearer",
"ha_auth_provider": "homeassistant"
} }
## Grant type refresh_token ## Grant type refresh_token
@ -289,7 +291,12 @@ class TokenView(HomeAssistantView):
"expires_in": int( "expires_in": int(
refresh_token.access_token_expiration.total_seconds() refresh_token.access_token_expiration.total_seconds()
), ),
} "ha_auth_provider": credential.auth_provider_type,
},
headers={
"Cache-Control": "no-store",
"Pragma": "no-cache",
},
) )
async def _async_handle_refresh_token(self, hass, data, remote_addr): async def _async_handle_refresh_token(self, hass, data, remote_addr):
@ -346,7 +353,11 @@ class TokenView(HomeAssistantView):
"expires_in": int( "expires_in": int(
refresh_token.access_token_expiration.total_seconds() refresh_token.access_token_expiration.total_seconds()
), ),
} },
headers={
"Cache-Control": "no-store",
"Pragma": "no-cache",
},
) )

View File

@ -81,6 +81,7 @@ async def test_login_new_user_and_trying_refresh_token(hass, aiohttp_client):
assert ( assert (
await hass.auth.async_validate_access_token(tokens["access_token"]) is not None await hass.auth.async_validate_access_token(tokens["access_token"]) is not None
) )
assert tokens["ha_auth_provider"] == "insecure_example"
# Use refresh token to get more tokens. # Use refresh token to get more tokens.
resp = await client.post( resp = await client.post(