| using ProtoBuf; | |||||
| namespace GrpcShared | |||||
| { | |||||
| [ProtoContract] | |||||
| public class AuthParams | |||||
| { | |||||
| [ProtoMember(1)] | |||||
| public string ClientId { get; set; } | |||||
| [ProtoMember(2)] | |||||
| public string RedirectURI { get; set; } | |||||
| [ProtoMember(3)] | |||||
| public string Scope { get; set; } | |||||
| } | |||||
| } |
| [ProtoContract] | [ProtoContract] | ||||
| public class SearchDetails | public class SearchDetails | ||||
| { | { | ||||
| [ProtoContract] | |||||
| public partial class SearchContracts | public partial class SearchContracts | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public Tracks? Tracks { get; set; } | public Tracks? Tracks { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Tracks | public partial class Tracks | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public Item[]? Items { get; set; } | public Item[]? Items { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Item | public partial class Item | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Album | public partial class Album | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Image | public partial class Image | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public long Width { get; set; } | public long Width { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Artist | public partial class Artist | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class ExternalUrls | public partial class ExternalUrls | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] |
| [ProtoContract] | [ProtoContract] | ||||
| public class SearchResponse | public class SearchResponse | ||||
| { | { | ||||
| [ProtoContract] | |||||
| public partial class SearchContracts | public partial class SearchContracts | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public Tracks? Tracks { get; set; } | public Tracks? Tracks { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Tracks | public partial class Tracks | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public List<Item>? Items { get; set; } | public List<Item>? Items { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Item | public partial class Item | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Album | public partial class Album | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Image | public partial class Image | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public long Width { get; set; } | public long Width { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class Artist | public partial class Artist | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] | ||||
| public string Uri { get; set; } | public string Uri { get; set; } | ||||
| } | } | ||||
| [ProtoContract] | |||||
| public partial class ExternalUrls | public partial class ExternalUrls | ||||
| { | { | ||||
| [ProtoMember(1)] | [ProtoMember(1)] |
| <Project Sdk="Microsoft.NET.Sdk"> | |||||
| <Project Sdk="Microsoft.NET.Sdk"> | |||||
| <PropertyGroup> | <PropertyGroup> | ||||
| <OutputType>Library</OutputType> | <OutputType>Library</OutputType> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" /> | |||||
| <PackageReference Include="protobuf-net.BuildTools" Version="3.1.17"> | |||||
| <PrivateAssets>all</PrivateAssets> | |||||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||||
| </PackageReference> | |||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| using GrpcShared.DTO.Auth; | using GrpcShared.DTO.Auth; | ||||
| using ProtoBuf.Grpc.Configuration; | |||||
| namespace IdentityProvider.Services.Interfaces | |||||
| namespace GrpcShared.Interfaces | |||||
| { | { | ||||
| [Service] | |||||
| public interface IAuthService | public interface IAuthService | ||||
| { | { | ||||
| Task<CodeResponse> GetCode(AuthRequest request); | Task<CodeResponse> GetCode(AuthRequest request); | ||||
| Task<AuthResponse> GetAccessToken(CodeResponse code); | Task<AuthResponse> GetAccessToken(CodeResponse code); | ||||
| Task<AuthParams> GetAuthParams(); | |||||
| } | } | ||||
| } | } |
| <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | ||||
| <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | ||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | ||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | ||||
| <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | <ProjectReference Include="..\GrpcShared\GrpcShared.csproj" /> | ||||
| <ProjectReference Include="..\NemAnCore\NemAnBlazor.csproj" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | </Project> |
| using GrpcShared; | |||||
| using IdentityProvider.Services; | using IdentityProvider.Services; | ||||
| using Microsoft.AspNetCore.Server.Kestrel.Core; | |||||
| using ProtoBuf.Grpc.Server; | using ProtoBuf.Grpc.Server; | ||||
| using Microsoft.Extensions.Options; | |||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||
| #if DEBUG | |||||
| builder.WebHost.ConfigureKestrel(options => | |||||
| { | |||||
| options.ListenLocalhost(5050, o => o.Protocols = | |||||
| HttpProtocols.Http2); | |||||
| options.ListenLocalhost(5051, o => o.Protocols = | |||||
| HttpProtocols.Http1AndHttp2); | |||||
| }); | |||||
| #endif | |||||
| builder.Services.AddOptions(); | |||||
| // Additional configuration is required to successfully run gRPC on macOS. | // Additional configuration is required to successfully run gRPC on macOS. | ||||
| // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 | // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 | ||||
| builder.Services.Configure<AuthParams>(builder.Configuration.GetSection("AuthParams")); | |||||
| builder.Services.AddControllersWithViews(); | builder.Services.AddControllersWithViews(); | ||||
| builder.Services.AddRazorPages(); | builder.Services.AddRazorPages(); | ||||
| { | { | ||||
| "iisSettings": { | |||||
| "windowsAuthentication": false, | |||||
| "anonymousAuthentication": true, | |||||
| "iisExpress": { | |||||
| "applicationUrl": "http://localhost:28725", | |||||
| "sslPort": 44342 | |||||
| } | |||||
| }, | |||||
| "profiles": { | "profiles": { | ||||
| "IIS Express": { | |||||
| "commandName": "IISExpress", | |||||
| "launchBrowser": true, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "environmentVariables": { | |||||
| "ASPNETCORE_ENVIRONMENT": "Development" | |||||
| } | |||||
| }, | |||||
| "IdentityProvider": { | "IdentityProvider": { | ||||
| "commandName": "Project", | "commandName": "Project", | ||||
| "dotnetRunMessages": true, | |||||
| "launchBrowser": false, | |||||
| "applicationUrl": "http://localhost:5164;https://localhost:7164", | |||||
| "dotnetRunMessages": "true", | |||||
| "launchBrowser": true, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", | |||||
| "applicationUrl": "https://localhost:5001;http://localhost:5000", | |||||
| "environmentVariables": { | "environmentVariables": { | ||||
| "ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
| } | } |
| //using IdentityProvider.Protos.AuthService; | //using IdentityProvider.Protos.AuthService; | ||||
| using GrpcShared; | |||||
| using GrpcShared.DTO.Auth; | using GrpcShared.DTO.Auth; | ||||
| using IdentityProvider.Services.Interfaces; | |||||
| using GrpcShared.Interfaces; | |||||
| using Microsoft.Extensions.Options; | |||||
| namespace IdentityProvider.Services | namespace IdentityProvider.Services | ||||
| { | { | ||||
| public class AuthService :IAuthService | |||||
| public class AuthService : IAuthService | |||||
| { | { | ||||
| private readonly ILogger<AuthService> _logger; | private readonly ILogger<AuthService> _logger; | ||||
| public AuthService(ILogger<AuthService> logger) | |||||
| private readonly AuthParams _params; | |||||
| public AuthService(ILogger<AuthService> logger, IOptions<AuthParams> options ) | |||||
| { | { | ||||
| _logger = logger; | _logger = logger; | ||||
| _params = options.Value; | |||||
| } | } | ||||
| public Task<AuthResponse> GetAccessToken(CodeResponse code) | public Task<AuthResponse> GetAccessToken(CodeResponse code) | ||||
| { | { | ||||
| throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
| { | { | ||||
| throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
| } | } | ||||
| public async Task<AuthParams> GetAuthParams() | |||||
| { | |||||
| var authParams = new AuthParams { | |||||
| ClientId = _params.ClientId, | |||||
| RedirectURI = _params.RedirectURI, | |||||
| Scope =_params.Scope }; | |||||
| return await Task.FromResult(authParams); | |||||
| } | |||||
| } | } | ||||
| } | } |
| "EndpointDefaults": { | "EndpointDefaults": { | ||||
| "Protocols": "Http2" | "Protocols": "Http2" | ||||
| } | } | ||||
| }, | |||||
| "AuthParams": { | |||||
| "ClientId": "83e1d09876b049c4bb1953185a4b3bfb", | |||||
| "RedirectURI": "https://localhost:5001/", | |||||
| "Scope": "user-read-currently-playing user-read-email user-library-modify user-top-read" | |||||
| } | } | ||||
| } | } |
| <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | |||||
| <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | |||||
| <PropertyGroup> | <PropertyGroup> | ||||
| <TargetFramework>net6.0</TargetFramework> | <TargetFramework>net6.0</TargetFramework> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Google.Protobuf" Version="3.21.4" /> | |||||
| <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="Grpc.Tools" Version="2.47.0"> | |||||
| <PrivateAssets>all</PrivateAssets> | |||||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||||
| </PackageReference> | |||||
| <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" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> |
| @page "/" | @page "/" | ||||
| @using Grpc.Net.Client | @using Grpc.Net.Client | ||||
| @using Grpc.Net.Client.Web | @using Grpc.Net.Client.Web | ||||
| @using GrpcShared | |||||
| @using GrpcShared.DTO.Auth | |||||
| @using NemAnBlazor.Services.Interfaces | |||||
| @inject NavigationManager NavigationManager | @inject NavigationManager NavigationManager | ||||
| @inject IAuthClientService AuthService | |||||
| @*@inject ISearchClientService SearchService*@ | |||||
| <PageTitle>Index</PageTitle> | <PageTitle>Index</PageTitle> | ||||
| <h1>Pozdrav Diligent!</h1> | <h1>Pozdrav Diligent!</h1> | ||||
| @code { | @code { | ||||
| private async Task OnInitializedAsync() | |||||
| protected override async Task OnInitializedAsync() | |||||
| { | { | ||||
| //var response = await SearchService.GetListSearchAsync(new GrpcShared.DTO.Search.SearchRequest() { Query="venom", Type = "track"}); | |||||
| AuthParams authParams = await AuthService.GetAuthParams(); | |||||
| // await AuthService.GetAccessToken(new CodeResponse{ Code = "hello"}); | |||||
| AuthRequest request = new() { ResponseType = "code", Scope = authParams.Scope, ClientId = authParams.ClientId, RedirectURI = authParams.RedirectURI}; | |||||
| string url = $"https://accounts.spotify.com/en/authorize?client_id={request.ClientId}&redirect_uri={request.RedirectURI}&response_type={request.ResponseType}&scope={request.Scope}&show_dialog=true"; | |||||
| NavigationManager.NavigateTo(); | |||||
| NavigationManager.NavigateTo(url); | |||||
| } | } | ||||
| } | } |
| using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||||
| using NemAnBlazor; | using NemAnBlazor; | ||||
| using NemAnBlazor.Services; | using NemAnBlazor.Services; | ||||
| using NemAnBlazor.Services.Interface; | |||||
| using NemAnBlazor.Services.Interfaces; | |||||
| var builder = WebAssemblyHostBuilder.CreateDefault(args); | var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||||
| builder.RootComponents.Add<App>("#app"); | builder.RootComponents.Add<App>("#app"); | ||||
| }); | }); | ||||
| builder.Services.AddScoped<ISearchClientService, SearchClientService>(); | builder.Services.AddScoped<ISearchClientService, SearchClientService>(); | ||||
| builder.Services.AddScoped<IAuthClientService, AuthClientService>(); | |||||
| await builder.Build().RunAsync(); | await builder.Build().RunAsync(); | ||||
| using Grpc.Net.Client; | |||||
| using GrpcShared.DTO.Auth; | |||||
| using GrpcShared.Interfaces; | |||||
| using NemAnBlazor.Services.Interfaces; | |||||
| using ProtoBuf.Grpc.Client; | |||||
| using GrpcShared; | |||||
| namespace NemAnBlazor.Services | |||||
| { | |||||
| public class AuthClientService : IAuthClientService | |||||
| { | |||||
| private IAuthService _serviceClient; | |||||
| public AuthClientService(GrpcChannel grpcChannel) | |||||
| { | |||||
| _serviceClient = grpcChannel.CreateGrpcService<IAuthService>(); | |||||
| } | |||||
| public async Task<AuthResponse> GetAccessToken(CodeResponse code) | |||||
| { | |||||
| return await _serviceClient.GetAccessToken(code); | |||||
| } | |||||
| public async Task <AuthParams> GetAuthParams() | |||||
| { | |||||
| return await _serviceClient.GetAuthParams(); | |||||
| } | |||||
| public Task<CodeResponse> GetCode(AuthRequest request) | |||||
| { | |||||
| throw new NotImplementedException(); | |||||
| } | |||||
| } | |||||
| } |
| using GrpcShared; | |||||
| using GrpcShared.DTO.Auth; | |||||
| namespace NemAnBlazor.Services.Interfaces | |||||
| { | |||||
| public interface IAuthClientService | |||||
| { | |||||
| Task<CodeResponse> GetCode(AuthRequest request); | |||||
| Task<AuthResponse> GetAccessToken(CodeResponse code); | |||||
| Task<AuthParams> GetAuthParams(); | |||||
| } | |||||
| } |
| using GrpcShared.DTO.Search; | using GrpcShared.DTO.Search; | ||||
| namespace NemAnBlazor.Services.Interface | |||||
| namespace NemAnBlazor.Services.Interfaces | |||||
| { | { | ||||
| public interface ISearchClientService | public interface ISearchClientService | ||||
| { | { |
| using GrpcShared.DTO.Search; | using GrpcShared.DTO.Search; | ||||
| using GrpcShared.Interfaces; | using GrpcShared.Interfaces; | ||||
| using NemAnBlazor.Services.Interface; | |||||
| using NemAnBlazor.Services.Interfaces; | |||||
| namespace NemAnBlazor.Services | namespace NemAnBlazor.Services | ||||
| { | { |
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | </Project> |
| <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | <PackageReference Include="Grpc.AspNetCore" Version="2.40.0" /> | ||||
| <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | <PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" /> | ||||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" /> | ||||
| <PackageReference Include="protobuf-net.Grpc" Version="1.0.171" /> | |||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | <PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.152" /> | ||||
| <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | <PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.152" /> | ||||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> |