Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from zkhcohen/pkce-auth
Browse files Browse the repository at this point in the history
Pkce auth
  • Loading branch information
zkhcohen authored Apr 10, 2021
2 parents 770528a + 1460a63 commit 9301182
Show file tree
Hide file tree
Showing 311 changed files with 10,208 additions and 7,569 deletions.
77 changes: 77 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~


# Created by https://www.gitignore.io/api/visualstudio
# Edit at https://www.gitignore.io/?templates=visualstudio
Expand All @@ -8,6 +15,76 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

**/.idea/**

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# JetBrains templates
**___jb_tmp___


# User-specific files
*.rsuser
*.suo
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CHANGE LOG:

Beta 2.0: Improved performance. Removed 500 album restriction. Added automatic prompt to re-authenticate if computer resumes from sleep.
Beta 2.0.2: Fixed error log spam.
Release 2.0: Improved performance. Removed 500 album restriction. Added automatic prompt to re-authenticate if computer resumes from sleep.
Release 2.0.2: Fixed error log spam.
Beta 3.1: Upgraded all API methods to 6.x.x spec. Implemented PKCE auth method with token persistence and automatic renewal. General speed improvements.
Binary file added Plugins/EmbedIO.dll
Binary file not shown.
Binary file modified Plugins/SpotifyAPI.Web.Auth.dll
Binary file not shown.
Binary file modified Plugins/SpotifyAPI.Web.dll
Binary file not shown.
Binary file added Plugins/Swan.Lite.dll
Binary file not shown.
Binary file removed Plugins/Unosquare.Labs.EmbedIO.dll
Binary file not shown.
Binary file removed Plugins/Unosquare.Swan.Lite.dll
Binary file not shown.
Binary file modified Plugins/mb_Spotify-Plugin.dll
Binary file not shown.
6 changes: 4 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ Let me know if you encounter any bugs - "ZKHCOHEN" on the MusicBee Forums.

KNOWN ISSUES:

Performance issues due to a workaround I implemented because of a bug in the Spotify API. Adding/removing albums is slow. The first track you play after enabling the add-in is slow to load.
You have to re-authenticate hourly due to a limitation with the Spotify API. I plan to do this silently in the future.
The Spotify API is (incorrectly) reporting the following error in the MusicBee ErrorLog.dat file:

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property.
As a result, the unobserved exception was rethrown by the finalizer thread. ---> SpotifyAPI.Web.APIException: invalid_grant
89 changes: 89 additions & 0 deletions Source Files/Crypt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Xml;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;

namespace MusicBeePlugin
{
public partial class Plugin
{
public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, string EncryptionElementID, RSA Alg, string KeyName)
{
if (Doc == null)
throw new ArgumentNullException("Doc");
if (ElementToEncrypt == null)
throw new ArgumentNullException("ElementToEncrypt");
if (EncryptionElementID == null)
throw new ArgumentNullException("EncryptionElementID");
if (Alg == null)
throw new ArgumentNullException("Alg");
if (KeyName == null)
throw new ArgumentNullException("KeyName");

XmlElement elementToEncrypt = Doc.GetElementsByTagName(ElementToEncrypt)[0] as XmlElement;

if (elementToEncrypt == null)
{
throw new XmlException("The specified element was not found");
}
Aes sessionKey = null;

try
{
EncryptedXml eXml = new EncryptedXml();
EncryptedData edElement = new EncryptedData();
EncryptedKey ek = new EncryptedKey();
DataReference dRef = new DataReference();
KeyInfoName kin = new KeyInfoName();

sessionKey = Aes.Create();

byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, false);

edElement.Type = EncryptedXml.XmlEncElementUrl;
edElement.Id = EncryptionElementID;
edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url);

byte[] encryptedKey = EncryptedXml.EncryptKey(sessionKey.Key, Alg, false);

ek.CipherData = new CipherData(encryptedKey);
ek.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncRSA15Url);
dRef.Uri = "#" + EncryptionElementID;
ek.AddReference(dRef);
edElement.KeyInfo.AddClause(new KeyInfoEncryptedKey(ek));
kin.Value = KeyName;
ek.KeyInfo.AddClause(kin);
edElement.CipherData.CipherValue = encryptedElement;

EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false);
}
catch (Exception e)
{
throw e;
}
finally
{
if (sessionKey != null)
{
sessionKey.Clear();
}
}
}

public static void Decrypt(XmlDocument Doc, RSA Alg, string KeyName)
{
if (Doc == null)
throw new ArgumentNullException("Doc");
if (Alg == null)
throw new ArgumentNullException("Alg");
if (KeyName == null)
throw new ArgumentNullException("KeyName");

EncryptedXml exml = new EncryptedXml(Doc);

exml.AddKeyNameMapping(KeyName, Alg);
exml.DecryptDocument();
}

}
}
Loading

0 comments on commit 9301182

Please sign in to comment.