|
@@ -111,81 +111,89 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
|
|
Token = token
|
|
|
};
|
|
|
|
|
|
- AuthenticationInfo originalAuthenticationInfo = null;
|
|
|
- if (!string.IsNullOrWhiteSpace(token))
|
|
|
+ if (string.IsNullOrWhiteSpace(token))
|
|
|
{
|
|
|
- var result = _authRepo.Get(new AuthenticationInfoQuery
|
|
|
- {
|
|
|
- AccessToken = token
|
|
|
- });
|
|
|
+ // Request doesn't contain a token.
|
|
|
+ return (null, null);
|
|
|
+ }
|
|
|
|
|
|
- originalAuthenticationInfo = result.Items.Count > 0 ? result.Items[0] : null;
|
|
|
+ var result = _authRepo.Get(new AuthenticationInfoQuery
|
|
|
+ {
|
|
|
+ AccessToken = token
|
|
|
+ });
|
|
|
|
|
|
- if (originalAuthenticationInfo != null)
|
|
|
- {
|
|
|
- var updateToken = false;
|
|
|
+ var originalAuthenticationInfo = result.Items.Count > 0 ? result.Items[0] : null;
|
|
|
|
|
|
- // TODO: Remove these checks for IsNullOrWhiteSpace
|
|
|
- if (string.IsNullOrWhiteSpace(authInfo.Client))
|
|
|
- {
|
|
|
- authInfo.Client = originalAuthenticationInfo.AppName;
|
|
|
- }
|
|
|
+ if (originalAuthenticationInfo != null)
|
|
|
+ {
|
|
|
+ var updateToken = false;
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(authInfo.DeviceId))
|
|
|
- {
|
|
|
- authInfo.DeviceId = originalAuthenticationInfo.DeviceId;
|
|
|
- }
|
|
|
+ // TODO: Remove these checks for IsNullOrWhiteSpace
|
|
|
+ if (string.IsNullOrWhiteSpace(authInfo.Client))
|
|
|
+ {
|
|
|
+ authInfo.Client = originalAuthenticationInfo.AppName;
|
|
|
+ }
|
|
|
|
|
|
- // Temporary. TODO - allow clients to specify that the token has been shared with a casting device
|
|
|
- var allowTokenInfoUpdate = authInfo.Client == null || authInfo.Client.IndexOf("chromecast", StringComparison.OrdinalIgnoreCase) == -1;
|
|
|
+ if (string.IsNullOrWhiteSpace(authInfo.DeviceId))
|
|
|
+ {
|
|
|
+ authInfo.DeviceId = originalAuthenticationInfo.DeviceId;
|
|
|
+ }
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(authInfo.Device))
|
|
|
- {
|
|
|
- authInfo.Device = originalAuthenticationInfo.DeviceName;
|
|
|
- }
|
|
|
- else if (!string.Equals(authInfo.Device, originalAuthenticationInfo.DeviceName, StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- if (allowTokenInfoUpdate)
|
|
|
- {
|
|
|
- updateToken = true;
|
|
|
- originalAuthenticationInfo.DeviceName = authInfo.Device;
|
|
|
- }
|
|
|
- }
|
|
|
+ // Temporary. TODO - allow clients to specify that the token has been shared with a casting device
|
|
|
+ var allowTokenInfoUpdate = authInfo.Client == null || authInfo.Client.IndexOf("chromecast", StringComparison.OrdinalIgnoreCase) == -1;
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(authInfo.Version))
|
|
|
- {
|
|
|
- authInfo.Version = originalAuthenticationInfo.AppVersion;
|
|
|
- }
|
|
|
- else if (!string.Equals(authInfo.Version, originalAuthenticationInfo.AppVersion, StringComparison.OrdinalIgnoreCase))
|
|
|
+ if (string.IsNullOrWhiteSpace(authInfo.Device))
|
|
|
+ {
|
|
|
+ authInfo.Device = originalAuthenticationInfo.DeviceName;
|
|
|
+ }
|
|
|
+ else if (!string.Equals(authInfo.Device, originalAuthenticationInfo.DeviceName, StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ if (allowTokenInfoUpdate)
|
|
|
{
|
|
|
- if (allowTokenInfoUpdate)
|
|
|
- {
|
|
|
- updateToken = true;
|
|
|
- originalAuthenticationInfo.AppVersion = authInfo.Version;
|
|
|
- }
|
|
|
+ updateToken = true;
|
|
|
+ originalAuthenticationInfo.DeviceName = authInfo.Device;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if ((DateTime.UtcNow - originalAuthenticationInfo.DateLastActivity).TotalMinutes > 3)
|
|
|
+ if (string.IsNullOrWhiteSpace(authInfo.Version))
|
|
|
+ {
|
|
|
+ authInfo.Version = originalAuthenticationInfo.AppVersion;
|
|
|
+ }
|
|
|
+ else if (!string.Equals(authInfo.Version, originalAuthenticationInfo.AppVersion, StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ if (allowTokenInfoUpdate)
|
|
|
{
|
|
|
- originalAuthenticationInfo.DateLastActivity = DateTime.UtcNow;
|
|
|
updateToken = true;
|
|
|
+ originalAuthenticationInfo.AppVersion = authInfo.Version;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (!originalAuthenticationInfo.UserId.Equals(Guid.Empty))
|
|
|
- {
|
|
|
- authInfo.User = _userManager.GetUserById(originalAuthenticationInfo.UserId);
|
|
|
+ if ((DateTime.UtcNow - originalAuthenticationInfo.DateLastActivity).TotalMinutes > 3)
|
|
|
+ {
|
|
|
+ originalAuthenticationInfo.DateLastActivity = DateTime.UtcNow;
|
|
|
+ updateToken = true;
|
|
|
+ }
|
|
|
|
|
|
- if (authInfo.User != null && !string.Equals(authInfo.User.Username, originalAuthenticationInfo.UserName, StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- originalAuthenticationInfo.UserName = authInfo.User.Username;
|
|
|
- updateToken = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!originalAuthenticationInfo.UserId.Equals(Guid.Empty))
|
|
|
+ {
|
|
|
+ authInfo.User = _userManager.GetUserById(originalAuthenticationInfo.UserId);
|
|
|
|
|
|
- if (updateToken)
|
|
|
+ if (authInfo.User != null && !string.Equals(authInfo.User.Username, originalAuthenticationInfo.UserName, StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
- _authRepo.Update(originalAuthenticationInfo);
|
|
|
+ originalAuthenticationInfo.UserName = authInfo.User.Username;
|
|
|
+ updateToken = true;
|
|
|
}
|
|
|
+
|
|
|
+ authInfo.IsApiKey = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ authInfo.IsApiKey = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (updateToken)
|
|
|
+ {
|
|
|
+ _authRepo.Update(originalAuthenticationInfo);
|
|
|
}
|
|
|
}
|
|
|
|