Add api key functions

This commit is contained in:
Luke Pulverenti
2014-07-11 22:31:08 -04:00
parent 59de5c0d14
commit b5641013ce
16 changed files with 168 additions and 39 deletions

View File

@@ -233,5 +233,8 @@
"OptionBlockGames": "Games",
"OptionBlockLiveTvPrograms": "Live TV Programs",
"OptionBlockLiveTvChannels": "Live TV Channels",
"OptionBlockChannelContent": "Internet Channel Content"
"OptionBlockChannelContent": "Internet Channel Content",
"ButtonRevoke": "Revoke",
"MessageConfirmRevokeApiKey": "Are you sure you wish to revoke this api key? The application's connection to Media Browser will be abruptly terminated.",
"HeaderConfirmRevokeApiKey": "Revoke Api Key"
}

View File

@@ -849,7 +849,7 @@
"LabelXbmcMetadataEnablePathSubstitutionHelp2": "See path substitution.",
"LabelGroupChannelsIntoViews": "Display the following channels directly within my views:",
"LabelGroupChannelsIntoViewsHelp": "If enabled, these channels will be displayed directly alongside other views. If disabled, they'll be displayed within a separate Channels view.",
"LabelDisplayCollectionsView": "Display a Collections view to show movie collections",
"LabelDisplayCollectionsView": "Display a collections view to show movie collections",
"LabelXbmcMetadataEnableExtraThumbs": "Copy extrafanart into extrathumbs",
"LabelXbmcMetadataEnableExtraThumbsHelp": "When downloading images they can be saved into both extrafanart and extrathumbs for maximum Xbmc skin compatibility.",
"TabServices": "Services",
@@ -870,5 +870,17 @@
"LabelImagesByName": "Images by name:",
"LabelTranscodingTemporaryFiles": "Transcoding temporary files:",
"HeaderLatestMusic": "Latest Music",
"HeaderBranding": "Branding"
"HeaderBranding": "Branding",
"HeaderApiKeys": "Api Keys",
"HeaderApiKeysHelp": "External applications are required to have an Api key in order to communicate with Media Browser. Keys are issued by logging in with a Media Browser account, or by manually granting the application a key.",
"HeaderApiKey": "Api Key",
"HeaderApp": "App",
"HeaderDevice": "Device",
"HeaderUser": "User",
"HeaderDateIssued": "Date Issued",
"LabelChapterName": "Chapter {0}",
"HeaderNewApiKey": "New Api Key",
"LabelAppName": "App name",
"LabelAppNameExample": "Example: Sickbeard, NzbDrone",
"HeaderNewApiKeyHelp": "Grant an application permission to communicate with Media Browser."
}

View File

@@ -283,11 +283,11 @@ namespace MediaBrowser.Server.Implementations.Security
}
info.IsActive = reader.GetBoolean(6);
info.DateCreated = reader.GetDateTime(7);
info.DateCreated = reader.GetDateTime(7).ToUniversalTime();
if (!reader.IsDBNull(8))
{
info.DateRevoked = reader.GetDateTime(8);
info.DateRevoked = reader.GetDateTime(8).ToUniversalTime();
}
return info;

View File

@@ -1210,15 +1210,15 @@ namespace MediaBrowser.Server.Implementations.Session
/// <returns>Task{SessionInfo}.</returns>
/// <exception cref="System.UnauthorizedAccessException">Invalid user or password entered.</exception>
/// <exception cref="UnauthorizedAccessException"></exception>
public async Task<AuthenticationResult> AuthenticateNewSession(string username,
string password,
string clientType,
string appVersion,
string deviceId,
string deviceName,
public async Task<AuthenticationResult> AuthenticateNewSession(string username,
string password,
string clientType,
string appVersion,
string deviceId,
string deviceName,
string remoteEndPoint)
{
var result = (IsLocalhost(remoteEndPoint) && string.Equals(clientType, "Dashboard", StringComparison.OrdinalIgnoreCase)) ||
var result = (IsLocalhost(remoteEndPoint) && string.Equals(clientType, "Dashboard", StringComparison.OrdinalIgnoreCase)) ||
await _userManager.AuthenticateUser(username, password).ConfigureAwait(false);
if (!result)
@@ -1332,6 +1332,11 @@ namespace MediaBrowser.Server.Implementations.Session
}
}
public Task RevokeToken(string token)
{
return Logout(token);
}
private bool IsLocalhost(string remoteEndpoint)
{
if (string.IsNullOrWhiteSpace(remoteEndpoint))

View File

@@ -62,14 +62,28 @@ namespace MediaBrowser.Server.Implementations.Session
void connection_Closed(object sender, EventArgs e)
{
var capabilities = new SessionCapabilities
if (!GetActiveSockets().Any())
{
PlayableMediaTypes = Session.PlayableMediaTypes,
SupportedCommands = Session.SupportedCommands,
SupportsMediaControl = SupportsMediaControl
};
try
{
_sessionManager.ReportSessionEnded(Session.Id);
}
catch (Exception ex)
{
_logger.ErrorException("Error reporting session ended.", ex);
}
}
else
{
var capabilities = new SessionCapabilities
{
PlayableMediaTypes = Session.PlayableMediaTypes,
SupportedCommands = Session.SupportedCommands,
SupportsMediaControl = SupportsMediaControl
};
_sessionManager.ReportCapabilities(Session.Id, capabilities);
_sessionManager.ReportCapabilities(Session.Id, capabilities);
}
}
private IWebSocketConnection GetActiveSocket()