| using ProtoBuf; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace GrpcShared.DTO.Track | |||||
| { | |||||
| [ProtoContract] | |||||
| public class TrackResponse | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public int? Timestamp{ get; set; } | |||||
| [ProtoMember(2)] | |||||
| public int? Progress_ms { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public bool? Is_playing { get; set; } | |||||
| [ProtoMember(4)] | |||||
| public Item? Item { get; set; } | |||||
| } | |||||
| [ProtoContract] | |||||
| public class Item | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public Album? Album { get; set; } | |||||
| [ProtoMember(2)] | |||||
| public Artist[]? Artists { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public string? Id { get; set; } | |||||
| [ProtoMember(4)] | |||||
| public string? Name { get; set; } | |||||
| [ProtoMember(5)] | |||||
| public string? Href { get; set; } | |||||
| } | |||||
| [ProtoContract] | |||||
| public class Album | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public string? Id { get; set; } | |||||
| [ProtoMember(2)] | |||||
| public string? Name { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public Image[]? Images { get; set; } | |||||
| [ProtoMember(4)] | |||||
| public string? Href { get; set; } | |||||
| } | |||||
| [ProtoContract] | |||||
| public class Artist | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public string? Id { get; set; } | |||||
| [ProtoMember(2)] | |||||
| public string? Name { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public string? Href { get; set; } | |||||
| } | |||||
| [ProtoContract] | |||||
| public class Image | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public int? Height{ get; set; } | |||||
| [ProtoMember(2)] | |||||
| public string? Url { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public int? Width { get; set; } | |||||
| } | |||||
| } |
| using GrpcShared.DTO.Track; | |||||
| using ProtoBuf.Grpc.Configuration; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace GrpcShared.Interfaces | |||||
| { | |||||
| [Service] | |||||
| public interface IStatsService | |||||
| { | |||||
| Task<TrackResponse> GetCurrentlyPlayingTrack(string token); | |||||
| } | |||||
| } |
| <Router AppAssembly="@typeof(App).Assembly"> | |||||
| <Found Context="routeData"> | |||||
| <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | |||||
| <CascadingAuthenticationState> | |||||
| <Router AppAssembly="@typeof(App).Assembly"> | |||||
| <Found Context="routeData"> | |||||
| <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" > | |||||
| <NotAuthorized>Sorry nisi autorizovan</NotAuthorized> | |||||
| </AuthorizeRouteView> | |||||
| <FocusOnNavigate RouteData="@routeData" Selector="h1" /> | <FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||||
| </Found> | </Found> | ||||
| <NotFound> | <NotFound> | ||||
| </LayoutView> | </LayoutView> | ||||
| </NotFound> | </NotFound> | ||||
| </Router> | </Router> | ||||
| </CascadingAuthenticationState> |
| using Blazored.SessionStorage; | |||||
| using System.Security.Claims; | |||||
| namespace NemAnBlazor | |||||
| { | |||||
| public class AuthProvider : AuthenticationStateProvider | |||||
| { | |||||
| private readonly ISessionStorageService _sessionStorage; | |||||
| public AuthProvider(ISessionStorageService sessionStorage) | |||||
| { | |||||
| _sessionStorage = sessionStorage; | |||||
| } | |||||
| public override async Task<AuthenticationState> GetAuthenticationStateAsync() | |||||
| { | |||||
| string token = await _sessionStorage.GetItemAsync<string>("token"); | |||||
| ClaimsIdentity identity = new (); | |||||
| ClaimsPrincipal user = new (identity); | |||||
| AuthenticationState state = new(user); | |||||
| NotifyAuthenticationStateChanged(Task.FromResult(state)); | |||||
| return state; | |||||
| } | |||||
| } | |||||
| } |
| <PackageReference Include="Blazored.SessionStorage" Version="2.2.0" /> | <PackageReference Include="Blazored.SessionStorage" Version="2.2.0" /> | ||||
| <PackageReference Include="Grpc.Net.Client" Version="2.47.0" /> | <PackageReference Include="Grpc.Net.Client" Version="2.47.0" /> | ||||
| <PackageReference Include="Grpc.Net.Client.Web" Version="2.47.0" /> | <PackageReference Include="Grpc.Net.Client.Web" Version="2.47.0" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.8" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" /> | ||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> |
| @inject NavigationManager NavigationMgr | @inject NavigationManager NavigationMgr | ||||
| @inject IAuthClientService AuthService | @inject IAuthClientService AuthService | ||||
| @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | @inject Blazored.SessionStorage.ISessionStorageService sessionStorage | ||||
| <PageTitle>Callback page</PageTitle> | |||||
| <PageTitle>Redirecting...</PageTitle> | |||||
| <p role="status">Current count: @currentCount</p> | |||||
| <p role="status">Loading...</p> | |||||
| <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | |||||
| @code { | @code { | ||||
| private int currentCount = 0; | |||||
| private void IncrementCount() | |||||
| { | |||||
| currentCount++; | |||||
| } | |||||
| protected override async Task OnInitializedAsync() | protected override async Task OnInitializedAsync() | ||||
| { | { | ||||
| string url = NavigationMgr.Uri; | string url = NavigationMgr.Uri; |
| @page "/home" | @page "/home" | ||||
| <h3>Home</h3> | <h3>Home</h3> | ||||
| <p>pozdrav, login radi</p> | |||||
| <p>login radi</p> | |||||
| <AuthorizeView> | |||||
| <Authorized> | |||||
| <p>autorizovan si</p> | |||||
| </Authorized> | |||||
| <NotAuthorized> | |||||
| <p>nisi autorizovan</p> | |||||
| </NotAuthorized> | |||||
| </AuthorizeView> | |||||
| @code { | @code { | ||||
| } | } |
| global using Microsoft.AspNetCore.Components.Authorization; | |||||
| using Blazored.SessionStorage; | using Blazored.SessionStorage; | ||||
| using Grpc.Net.Client; | using Grpc.Net.Client; | ||||
| using Grpc.Net.Client.Web; | using Grpc.Net.Client.Web; | ||||
| builder.Services.AddScoped<ITrackClientService, TrackClientService>(); | builder.Services.AddScoped<ITrackClientService, TrackClientService>(); | ||||
| builder.Services.AddScoped<IAuthClientService, AuthClientService>(); | builder.Services.AddScoped<IAuthClientService, AuthClientService>(); | ||||
| builder.Services.AddBlazoredSessionStorage(); | builder.Services.AddBlazoredSessionStorage(); | ||||
| builder.Services.AddScoped<AuthenticationStateProvider, AuthProvider>(); | |||||
| builder.Services.AddAuthorizationCore(); | |||||
| await builder.Build().RunAsync(); | await builder.Build().RunAsync(); | ||||
| namespace NemAnBlazor.Services.Interfaces | |||||
| { | |||||
| public interface IStatsClientService | |||||
| { | |||||
| } | |||||
| } |
| using NemAnBlazor.Services.Interfaces; | |||||
| namespace NemAnBlazor.Services | |||||
| { | |||||
| public class StatsClientService :IStatsClientService | |||||
| { | |||||
| } | |||||
| } |
| @using Microsoft.JSInterop | @using Microsoft.JSInterop | ||||
| @using NemAnBlazor | @using NemAnBlazor | ||||
| @using NemAnBlazor.Shared | @using NemAnBlazor.Shared | ||||
| @using System.Web | |||||
| @using System.Web | |||||
| @using Microsoft.AspNetCore.Components.Authorization |
| | |||||
| using GrpcShared.DTO.Track; | |||||
| using GrpcShared.Interfaces; | |||||
| namespace SpotifyService.Services | |||||
| { | |||||
| public class StatsService : IStatsService | |||||
| { | |||||
| private readonly IHttpClientFactory _httpClientFactory; | |||||
| public StatsService(IHttpClientFactory httpClientFactory) | |||||
| { | |||||
| _httpClientFactory = httpClientFactory; | |||||
| } | |||||
| public Task<TrackResponse> GetCurrentlyPlayingTrack(string token) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } |