Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: New auth #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
15 changes: 7 additions & 8 deletions Lastfm-Scrobbler/Api/LastfmApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ public class LastfmApiClient : BaseLastfmApiClient
{
public LastfmApiClient(IHttpClient httpClient, IJsonSerializer jsonSerializer) : base(httpClient, jsonSerializer) { }

public async Task<MobileSessionResponse> RequestSession(string username, string password)
public async Task<SessionResponse> GetSession(string token)
{
//Build request object
var request = new MobileSessionRequest
var request = new SessionRequest
{
Username = username,
Password = password,
Token = token,
Secure = true
};

var response = await Post<MobileSessionRequest, MobileSessionResponse>(request);
var response = await Post<SessionRequest, SessionResponse>(request).ConfigureAwait(false);

//Log the key for debugging
if (response != null)
Plugin.Logger.Info("{0} successfully logged into Last.fm", username);
if (response == null)
Plugin.Logger.Info("{0} failed to login into Last.fm");

return response;
}
Expand Down Expand Up @@ -147,4 +146,4 @@ public Task<bool> UnloveTrack(Audio item, LastfmUser user)
return LoveTrack(item, user, false);
}
}
}
}
5 changes: 3 additions & 2 deletions Lastfm-Scrobbler/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace LastfmScrobbler.Configuration
{
using System.Collections.Generic;
using Models;
using MediaBrowser.Model.Plugins;

Expand All @@ -8,14 +9,14 @@
/// </summary>
public class PluginConfiguration : BasePluginConfiguration
{
public LastfmUser[] LastfmUsers { get; set; }
public List<LastfmUser> LastfmUsers { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="PluginConfiguration" /> class.
/// </summary>
public PluginConfiguration()
{
LastfmUsers = new LastfmUser[] { };
LastfmUsers = new List<LastfmUser>();
}
}
}
19 changes: 13 additions & 6 deletions Lastfm-Scrobbler/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
<select id="user" name="user"></select>
</li>
<li>
<label for="username">Username</label>
<input type="text" id="username" name="username" required="required" placeholder="Your Last.fm Username" />
</li>
<li>
<label for="password">Password</label>
<input type="password" id="password" name="password" required="required" placeholder="Your Last.fm Password" />
<div class="">
<button id="connect">Connect to Last.fm</button>
</div>
</li>
<li>
<input type="checkbox" class="chkStandardFilter" name="optionScrobble" id="optionScrobble" data-mini="true" />
Expand All @@ -42,6 +39,7 @@

var LastfmScrobblerConfigurationPage = {
_pluginUniqueId: "1f5e1261-1e09-4bed-8839-dc07afe096c2",
_apiKey: "e85c2d4e649f4a01dbfec778d758ab2e",
_users: [],
_config: [],

Expand All @@ -68,6 +66,7 @@
this.$el.find('#LastfmScrobblerConfigurationForm').on('submit', this, this.onSubmit);
this.$el.find('#user').on('change', this, $.proxy(this.onUserChange, this));
this.$el.find("#removeUser").on('click', $.proxy(this.removeUser, this));
this.$el.find("#connect").on('click', $.proxy(this.redirectToLastfm, this));

var loadConfig = this.loadConfiguration();
var loadUsers = this.loadUsers().then($.proxy(this.buildUserList, this));
Expand Down Expand Up @@ -110,6 +109,14 @@
.selectmenu("refresh");
},

redirectToLastfm: function() {
var userId = this.getCurrentSelectedUserId();

var callbackUrl = "LastFm/Callback?UserId=" + userId + "&retUrl=" + window.location;

window.location = "http://www.last.fm/api/auth/?api_key=" + this._apiKey + "&cb=" + ApiClient.getUrl(encodeURIComponent(callbackUrl));
},

populateInputs: function (userData) {
var data = $.extend({}, this.configDefaults, userData);

Expand Down
181 changes: 91 additions & 90 deletions Lastfm-Scrobbler/Lastfm-Scrobbler.csproj
Original file line number Diff line number Diff line change
@@ -1,96 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{30B2A395-5E43-454F-8093-DAF307D6D4FB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LastfmScrobbler</RootNamespace>
<AssemblyName>Lastfm-Scrobbler</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MediaBrowser.Common, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Common.3.0.701\lib\portable-net45+win8+wpa81\MediaBrowser.Common.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.Controller, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.701\lib\net45\MediaBrowser.Controller.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.Model, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Common.3.0.701\lib\portable-net45+win8+wpa81\MediaBrowser.Model.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Api\BaseLastfmApiClient.cs" />
<Compile Include="Api\LastfmApiClient.cs" />
<Compile Include="Configuration\PluginConfiguration.cs" />
<Compile Include="Configuration\ScrobblerConfigurationPage.cs" />
<Compile Include="Models\Requests\BaseRequest.cs" />
<Compile Include="Models\LastfmUser.cs" />
<Compile Include="Models\MobileSession.cs" />
<Compile Include="Models\Requests\MobileSessionRequest.cs" />
<Compile Include="Models\Requests\NowPlayingRequest.cs" />
<Compile Include="Models\Requests\TrackLoveRequest.cs" />
<Compile Include="Models\Responses\BaseResponse.cs" />
<Compile Include="Models\Responses\LovedTracksResponse.cs" />
<Compile Include="Models\Responses\MobileSessionResponse.cs" />
<Compile Include="Models\Requests\ScrobbleRequest.cs" />
<Compile Include="Models\Responses\ScrobbleResponse.cs" />
<Compile Include="Models\Scrobble.cs" />
<Compile Include="Models\Tracks.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Strings.cs" />
<Compile Include="RestApi.cs" />
<Compile Include="ServerEntryPoint.cs" />
<Compile Include="Utils\Helpers.cs" />
<Compile Include="Utils\UserHelpers.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Configuration\configPage.html" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetPath)" "%25AppData%25\MediaBrowser-Server\Plugins\" /y</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{30B2A395-5E43-454F-8093-DAF307D6D4FB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LastfmScrobbler</RootNamespace>
<AssemblyName>Lastfm-Scrobbler</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MediaBrowser.Common, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Common.3.0.701\lib\portable-net45+win8+wpa81\MediaBrowser.Common.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.Controller, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.701\lib\net45\MediaBrowser.Controller.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.Model, Version=3.2.17.15, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Common.3.0.701\lib\portable-net45+win8+wpa81\MediaBrowser.Model.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Api\BaseLastfmApiClient.cs" />
<Compile Include="Api\LastfmApiClient.cs" />
<Compile Include="Configuration\PluginConfiguration.cs" />
<Compile Include="Configuration\ScrobblerConfigurationPage.cs" />
<Compile Include="Models\Requests\BaseRequest.cs" />
<Compile Include="Models\LastfmUser.cs" />
<Compile Include="Models\Requests\NowPlayingRequest.cs" />
<Compile Include="Models\Requests\SessionRequest.cs" />
<Compile Include="Models\Requests\TrackLoveRequest.cs" />
<Compile Include="Models\Responses\BaseResponse.cs" />
<Compile Include="Models\Responses\GetUserInfoResponse.cs" />
<Compile Include="Models\Responses\LovedTracksResponse.cs" />
<Compile Include="Models\Requests\ScrobbleRequest.cs" />
<Compile Include="Models\Responses\ScrobbleResponse.cs" />
<Compile Include="Models\Responses\SessionResponse.cs" />
<Compile Include="Models\Scrobble.cs" />
<Compile Include="Models\Session.cs" />
<Compile Include="Models\Tracks.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Strings.cs" />
<Compile Include="RestApi.cs" />
<Compile Include="ServerEntryPoint.cs" />
<Compile Include="Utils\Helpers.cs" />
<Compile Include="Utils\UserHelpers.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Configuration\configPage.html" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetPath)" "%25AppData%25\Emby-Server\Plugins\" /y</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
3 changes: 3 additions & 0 deletions Lastfm-Scrobbler/Models/LastfmUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

public class LastfmUser
{
/// <summary>
/// Last.fm Username
/// </summary>
public string Username { get; set; }

//We wont store the password, but instead store the session key since its a lifetime key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
using System.Collections.Generic;
using Resources;

public class MobileSessionRequest : BaseRequest
public class SessionRequest : BaseRequest
{
public string Password { get; set; }
public string Username { get; set; }
public string Token { get; set; }

public override string Method => Strings.Methods.GetMobileSession;
public override string Method => Strings.Methods.GetSession;

public override Dictionary<string, string> ToDictionary()
{
return new Dictionary<string, string>(base.ToDictionary())
{
{ "password", Password },
{ "username", Username },
{ "token", Token }
};
}
}
Expand Down
16 changes: 16 additions & 0 deletions Lastfm-Scrobbler/Models/Responses/GetUserInfoResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace LastfmScrobbler.Models.Responses
{
using System.Runtime.Serialization;

[DataContract]
public class GetUserInfoResponse : BaseResponse
{
public User User { get; set; }
}

[DataContract]
public class User
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using System.Runtime.Serialization;

[DataContract]
public class MobileSessionResponse : BaseResponse
public class SessionResponse : BaseResponse
{
[DataMember(Name="session")]
public MobileSession Session { get; set; }
public Session Session { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Runtime.Serialization;

[DataContract]
public class MobileSession
public class Session
{
[DataMember(Name = "name")]
public string Name { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Lastfm-Scrobbler/Resources/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Methods
{
public static string Scrobble = "track.scrobble";
public static string NowPlaying = "track.updateNowPlaying";
public static string GetMobileSession = "auth.getMobileSession";
public static string GetSession = "auth.getSession";
public static string TrackLove = "track.love";
public static string TrackUnlove = "track.unlove";
}
Expand Down
Loading