Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
API login and authorization
logging in to the spotify API, as well as authorizing use on mobile webview browsers
- Loading branch information
Chronos
authored and
Chronos
committed
Mar 19, 2023
1 parent
b622a26
commit 5242d29cff10effcf3ce9a4390258dc9bab8df19
Showing
21 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace app.Models; | ||
|
||
public record AuthResult { | ||
|
||
[JsonPropertyName("access_token")] | ||
public string AccessToken { get; set; } | ||
[JsonPropertyName("refresh_token")] | ||
public string RefreshToken { get; set; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
namespace app.Services; | ||
|
||
public interface ISpotifyService { | ||
|
||
Task<bool> Initialize(string authCode); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using app.Models; | ||
|
||
namespace app.Services; | ||
|
||
public class SpotifyService : ISpotifyService { | ||
private string accessToken; | ||
|
||
public SpotifyService() { | ||
} | ||
|
||
public async Task<bool> Initialize(string authCode) { | ||
|
||
var bytes = Encoding.UTF8.GetBytes($"{Constants.SpotifyClientId}:{Constants.SpotifyClientSecret}"); | ||
var authHeader = Convert.ToBase64String(bytes); | ||
|
||
var client = new HttpClient(); | ||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authHeader); | ||
|
||
var content = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>() { | ||
new("code", authCode), | ||
new("redirect_uri", Constants.RedirectUrl), | ||
new("grant_type", "authorization_code") | ||
}); | ||
|
||
var response = await client.PostAsync("https://accounts.spotify.com/api/token", content); | ||
|
||
var json = await response.Content.ReadAsStringAsync(); | ||
|
||
//deserializing token | ||
var result = JsonSerializer.Deserialize<AuthResult>(json); | ||
|
||
accessToken = result.AccessToken; | ||
return response.IsSuccessStatusCode; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 17.0.31611.283 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "app", "app\app.csproj", "{E40CBDBA-2A17-477A-B283-EB69BD81D28E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E40CBDBA-2A17-477A-B283-EB69BD81D28E}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} | ||
EndGlobalSection | ||
EndGlobal |
BIN
+8.5 KB
(150%)
bin/Debug/net7.0-ios/iossimulator-x64/app.app/app.dll
Binary file not shown.
BIN
+1.67 KB
(110%)
bin/Debug/net7.0-ios/iossimulator-x64/app.app/app.pdb
Binary file not shown.
BIN
+8.5 KB
(150%)
bin/Debug/net7.0-ios/iossimulator-x64/app.dll
Binary file not shown.
BIN
+1.67 KB
(110%)
bin/Debug/net7.0-ios/iossimulator-x64/app.pdb
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
objc[61091]: Class CDPCAReporter is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDPInternal.framework/CoreCDPInternal (0x15abd51d8) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDP.framework/CoreCDP (0x15376aeb0). One of the two will be used. Which one is undefined. | ||
objc[61091]: Class CDPCABackupRecoveryReporter is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDPInternal.framework/CoreCDPInternal (0x15abd5ef8) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDP.framework/CoreCDP (0x15376b0e0). One of the two will be used. Which one is undefined. | ||
objc[93152]: Class CDPCAReporter is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDPInternal.framework/CoreCDPInternal (0x15a5131d8) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDP.framework/CoreCDP (0x1530a8eb0). One of the two will be used. Which one is undefined. | ||
objc[93152]: Class CDPCABackupRecoveryReporter is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDPInternal.framework/CoreCDPInternal (0x15a513ef8) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/CoreCDP.framework/CoreCDP (0x1530a90e0). One of the two will be used. Which one is undefined. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
98378c31f6eaabff58f5bba47fe4fafa9dbcc3d9 | ||
634e2a0b790f7685ed393364c3f302be7651311d |
BIN
+8.5 KB
(150%)
obj/Debug/net7.0-ios/iossimulator-x64/app.dll
Binary file not shown.
BIN
+1.67 KB
(110%)
obj/Debug/net7.0-ios/iossimulator-x64/app.pdb
Binary file not shown.
BIN
+8.5 KB
(150%)
obj/Debug/net7.0-ios/iossimulator-x64/linked/app.dll
Binary file not shown.
BIN
+1.67 KB
(110%)
obj/Debug/net7.0-ios/iossimulator-x64/linked/app.pdb
Binary file not shown.
BIN
+2.5 KB
(130%)
obj/Debug/net7.0-ios/iossimulator-x64/ref/app.dll
Binary file not shown.
BIN
+2.5 KB
(130%)
obj/Debug/net7.0-ios/iossimulator-x64/refint/app.dll
Binary file not shown.