| @@ -16,15 +16,6 @@ namespace GrpcShared.DTO.Search | |||
| [ProtoMember(2)] | |||
| public string? Type { get; set; } | |||
| [ProtoMember(3)] | |||
| public string? Include_External { get; set; } | |||
| [ProtoMember(4)] | |||
| public int? Limit { get; set; } | |||
| [ProtoMember(5)] | |||
| public int? Offset { get; set; } | |||
| } | |||
| } | |||
| @@ -74,7 +74,7 @@ namespace GrpcShared.DTO.Search | |||
| public string? Name { get; set; } | |||
| [ProtoMember(5)] | |||
| public DateTimeOffset? ReleaseDate { get; set; } | |||
| public string? ReleaseDate { get; set; } | |||
| [ProtoMember(6)] | |||
| public int? TotalTracks { get; set; } | |||
| @@ -5,7 +5,7 @@ using ProtoBuf.Grpc.Server; | |||
| using Microsoft.Extensions.Options; | |||
| using GrpcShared.DTO.Auth; | |||
| using SpotifyService.Services; | |||
| using Blazored.SessionStorage; | |||
| using Blazored.LocalStorage; | |||
| var builder = WebApplication.CreateBuilder(args); | |||
| #if DEBUG | |||
| @@ -37,7 +37,7 @@ builder.Services.AddEndpointsApiExplorer(); | |||
| builder.Services.AddGrpc(); | |||
| builder.Services.AddCodeFirstGrpc(); | |||
| builder.Services.AddCodeFirstGrpcReflection(); | |||
| builder.Services.AddBlazoredSessionStorage(); | |||
| builder.Services.AddBlazoredLocalStorage(); | |||
| //call spotify api | |||
| builder.Services.AddHttpClient(); | |||
| @@ -1,5 +1,5 @@ | |||
| //using IdentityProvider.Protos.AuthService; | |||
| using Blazored.SessionStorage; | |||
| using Blazored.LocalStorage; | |||
| using Grpc.Net.Client; | |||
| using GrpcShared; | |||
| using GrpcShared.DTO; | |||
| @@ -15,7 +15,7 @@ | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Blazored.SessionStorage" Version="2.2.0" /> | |||
| <PackageReference Include="Blazored.LocalStorage" Version="4.2.0" /> | |||
| <PackageReference Include="Grpc.Net.Client" Version="2.47.0" /> | |||
| <PackageReference Include="Grpc.Net.Client.Web" Version="2.47.0" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.8" /> | |||
| @@ -2,7 +2,7 @@ | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @inject NavigationManager NavigationMgr | |||
| @inject IAuthClientService AuthService | |||
| @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | |||
| @inject Blazored.LocalStorage.ILocalStorageService localStorage | |||
| <PageTitle>Redirecting...</PageTitle> | |||
| @@ -24,8 +24,8 @@ | |||
| //if (response.access_token == null) NavigationMgr.NavigateTo("/"); | |||
| //store access token in local storage | |||
| await sessionStorage.SetItemAsync("token", response.AccessToken); | |||
| await sessionStorage.SetItemAsync("refresh_token", response.RefreshToken); | |||
| await localStorage.SetItemAsync("token", response.AccessToken); | |||
| await localStorage.SetItemAsync("refresh_token", response.RefreshToken); | |||
| //redirect to home | |||
| NavigationMgr.NavigateTo("/home"); | |||
| @@ -9,7 +9,7 @@ | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @using System.Diagnostics | |||
| @*@inject HttpClient Http*@ | |||
| @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | |||
| @inject Blazored.LocalStorage.ILocalStorageService localStorage | |||
| @inject ITrackClientService SearchService | |||
| @inject IAuthClientService AuthService | |||
| @@ -35,7 +35,7 @@ | |||
| private async Task Click() | |||
| { | |||
| var token = await sessionStorage.GetItemAsync<string>("token"); | |||
| var token = await localStorage.GetItemAsync<string>("token"); | |||
| TokenMessage tm = new() { Token = token }; | |||
| SearchRequest request = new() { Query = "aitch", Type = "track", Token = token }; | |||
| SearchResponse searchResponse = await SearchService.GetListSearchAsync(request); | |||
| @@ -2,7 +2,7 @@ | |||
| @using GrpcShared.DTO | |||
| @using GrpcShared.DTO.Track | |||
| @using NemAnBlazor.Services.Interfaces | |||
| @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | |||
| @inject Blazored.LocalStorage.ILocalStorageService localStorage | |||
| @inject IStatsClientService spotifyService | |||
| @inject ITrackClientService trackService | |||
| @@ -13,7 +13,7 @@ | |||
| @code { | |||
| protected override async Task OnInitializedAsync() | |||
| { | |||
| string tokenS = await sessionStorage.GetItemAsync<string>("token"); | |||
| string tokenS = await localStorage.GetItemAsync<string>("token"); | |||
| TokenMessage token = new TokenMessage{Token = tokenS}; | |||
| CurrentTrackResponse response = await spotifyService.GetCurrentlyPlayingTrack(token); | |||
| @@ -1,5 +1,5 @@ | |||
| global using Microsoft.AspNetCore.Components.Authorization; | |||
| using Blazored.SessionStorage; | |||
| using Blazored.LocalStorage; | |||
| using Grpc.Net.Client; | |||
| using Grpc.Net.Client.Web; | |||
| using Microsoft.AspNetCore.Components; | |||
| @@ -28,7 +28,7 @@ builder.Services.AddScoped<AuthenticationStateProvider, AuthClientService>(); | |||
| builder.Services.AddScoped<ITrackClientService, TrackClientService>(); | |||
| builder.Services.AddScoped<IAuthClientService, AuthClientService>(); | |||
| builder.Services.AddScoped<IStatsClientService, StatsClientService>(); | |||
| builder.Services.AddBlazoredSessionStorage(); | |||
| builder.Services.AddBlazoredLocalStorage(); | |||
| builder.Services.AddScoped<AuthenticationStateProvider, AuthClientService>(); | |||
| builder.Services.AddAuthorizationCore(); | |||
| @@ -8,7 +8,7 @@ using GrpcShared.DTO.User; | |||
| using GrpcShared.DTO; | |||
| using System.Security.Claims; | |||
| using Microsoft.AspNetCore.Components.Authorization; | |||
| using Blazored.SessionStorage; | |||
| using Blazored.LocalStorage; | |||
| namespace NemAnBlazor.Services | |||
| { | |||
| @@ -16,8 +16,8 @@ namespace NemAnBlazor.Services | |||
| { | |||
| private IAuthService _serviceClient; | |||
| private ISessionStorageService _sessionStorage; | |||
| public AuthClientService(GrpcChannel grpcChannel, ISessionStorageService sessionStorage) | |||
| private ILocalStorageService _sessionStorage; | |||
| public AuthClientService(GrpcChannel grpcChannel, ILocalStorageService sessionStorage) | |||
| { | |||
| _serviceClient = grpcChannel.CreateGrpcService<IAuthService>(); | |||
| _sessionStorage = sessionStorage; | |||
| @@ -20,5 +20,15 @@ namespace SpotifyService.HttpUtils | |||
| return response; | |||
| } | |||
| public static async Task PutData(HttpClient client, string url, string token) | |||
| { | |||
| //add header | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + token); | |||
| //get request | |||
| await client.PutAsync(url, null); | |||
| } | |||
| } | |||
| } | |||
| @@ -59,17 +59,15 @@ namespace SpotifyService.Services | |||
| { | |||
| var client = _httpClientFactory.CreateClient("HttpClient"); | |||
| client.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Bearer " + request.Token); | |||
| var param = new Dictionary<string, List<string>>(); | |||
| param["ids"] = request.Ids!; | |||
| var query = UriUtil(param); | |||
| string url = $"me/tracks/{query}"; | |||
| await client.PutAsync($"me/tracks/{query}", null); | |||
| //the response type has nothing to do with the method, it's there so that the method can be called | |||
| await HttpUtils.HttpUtils<MultipleTrackResponse>.PutData(client, url, request.Token!); | |||
| } | |||
| public static string UriUtil(Dictionary<string, List<string>> param) | |||
| { | |||