Переглянути джерело

fixed connection with identity provider and blazor

tags/v1.1.0^2
anastasijasavov 3 роки тому
джерело
коміт
64e9d16749

+ 16
- 0
GrpcShared/DTO/Auth/AuthParams.cs Переглянути файл

@@ -0,0 +1,16 @@
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; }
}
}

+ 7
- 6
GrpcShared/DTO/Search/SearchDetails.cs Переглянути файл

@@ -10,12 +10,13 @@ namespace GrpcShared.DTO.Search
[ProtoContract]
public class SearchDetails
{
[ProtoContract]
public partial class SearchContracts
{
[ProtoMember(1)]
public Tracks? Tracks { get; set; }
}
[ProtoContract]
public partial class Tracks
{
[ProtoMember(1)]
@@ -26,7 +27,7 @@ namespace GrpcShared.DTO.Search

public Item[]? Items { get; set; }
}
[ProtoContract]
public partial class Item
{
[ProtoMember(1)]
@@ -72,7 +73,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class Album
{
[ProtoMember(1)]
@@ -107,7 +108,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class Image
{
[ProtoMember(1)]
@@ -122,7 +123,7 @@ namespace GrpcShared.DTO.Search

public long Width { get; set; }
}
[ProtoContract]
public partial class Artist
{
[ProtoMember(1)]
@@ -149,7 +150,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class ExternalUrls
{
[ProtoMember(1)]

+ 7
- 6
GrpcShared/DTO/Search/SearchResponse.cs Переглянути файл

@@ -10,12 +10,13 @@ namespace GrpcShared.DTO.Search
[ProtoContract]
public class SearchResponse
{
[ProtoContract]
public partial class SearchContracts
{
[ProtoMember(1)]
public Tracks? Tracks { get; set; }
}
[ProtoContract]
public partial class Tracks
{
[ProtoMember(1)]
@@ -26,7 +27,7 @@ namespace GrpcShared.DTO.Search

public List<Item>? Items { get; set; }
}
[ProtoContract]
public partial class Item
{
[ProtoMember(1)]
@@ -72,7 +73,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class Album
{
[ProtoMember(1)]
@@ -107,7 +108,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class Image
{
[ProtoMember(1)]
@@ -122,7 +123,7 @@ namespace GrpcShared.DTO.Search

public long Width { get; set; }
}
[ProtoContract]
public partial class Artist
{
[ProtoMember(1)]
@@ -149,7 +150,7 @@ namespace GrpcShared.DTO.Search

public string Uri { get; set; }
}
[ProtoContract]
public partial class ExternalUrls
{
[ProtoMember(1)]

+ 6
- 1
GrpcShared/GrpcShared.csproj Переглянути файл

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
@@ -8,6 +8,11 @@
</PropertyGroup>

<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" />
</ItemGroup>


+ 4
- 1
GrpcShared/Interfaces/IAuthService.cs Переглянути файл

@@ -1,10 +1,13 @@
using GrpcShared.DTO.Auth;
using ProtoBuf.Grpc.Configuration;

namespace IdentityProvider.Services.Interfaces
namespace GrpcShared.Interfaces
{
[Service]
public interface IAuthService
{
Task<CodeResponse> GetCode(AuthRequest request);
Task<AuthResponse> GetAccessToken(CodeResponse code);
Task<AuthParams> GetAuthParams();
}
}

+ 3
- 0
IdentityProvider/IdentityProvider.csproj Переглянути файл

@@ -10,12 +10,15 @@
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" />
<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.Reflection" Version="1.0.152" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GrpcShared\GrpcShared.csproj" />
<ProjectReference Include="..\NemAnCore\NemAnBlazor.csproj" />
</ItemGroup>

</Project>

+ 16
- 1
IdentityProvider/Program.cs Переглянути файл

@@ -1,11 +1,26 @@
using GrpcShared;
using IdentityProvider.Services;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using ProtoBuf.Grpc.Server;
using Microsoft.Extensions.Options;

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.
// 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.AddRazorPages();


+ 20
- 3
IdentityProvider/Properties/launchSettings.json Переглянути файл

@@ -1,10 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28725",
"sslPort": 44342
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IdentityProvider": {
"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": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

+ 17
- 3
IdentityProvider/Services/AuthService.cs Переглянути файл

@@ -1,17 +1,22 @@
//using IdentityProvider.Protos.AuthService;
using GrpcShared;
using GrpcShared.DTO.Auth;
using IdentityProvider.Services.Interfaces;
using GrpcShared.Interfaces;
using Microsoft.Extensions.Options;

namespace IdentityProvider.Services
{
public class AuthService :IAuthService
public class AuthService : IAuthService
{
private readonly ILogger<AuthService> _logger;
public AuthService(ILogger<AuthService> logger)
private readonly AuthParams _params;
public AuthService(ILogger<AuthService> logger, IOptions<AuthParams> options )
{
_logger = logger;
_params = options.Value;
}


public Task<AuthResponse> GetAccessToken(CodeResponse code)
{
throw new NotImplementedException();
@@ -21,5 +26,14 @@ namespace IdentityProvider.Services
{
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);
}
}
}

+ 5
- 0
IdentityProvider/appsettings.json Переглянути файл

@@ -10,5 +10,10 @@
"EndpointDefaults": {
"Protocols": "Http2"
}
},
"AuthParams": {
"ClientId": "83e1d09876b049c4bb1953185a4b3bfb",
"RedirectURI": "https://localhost:5001/",
"Scope": "user-read-currently-playing user-read-email user-library-modify user-top-read"
}
}

+ 2
- 6
NemAnCore/NemAnBlazor.csproj Переглянути файл

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -7,15 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.21.4" />
<PackageReference Include="Grpc.Net.Client" 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.DevServer" Version="6.0.7" PrivateAssets="all" />
<PackageReference Include="protobuf-net.Grpc" Version="1.0.171" />
</ItemGroup>

<ItemGroup>

+ 14
- 3
NemAnCore/Pages/Index.razor Переглянути файл

@@ -1,8 +1,12 @@
@page "/"
@using Grpc.Net.Client
@using Grpc.Net.Client.Web
@using GrpcShared
@using GrpcShared.DTO.Auth
@using NemAnBlazor.Services.Interfaces
@inject NavigationManager NavigationManager

@inject IAuthClientService AuthService
@*@inject ISearchClientService SearchService*@
<PageTitle>Index</PageTitle>

<h1>Pozdrav Diligent!</h1>
@@ -11,9 +15,16 @@ Dobrodošli u našu NemAn aplikaciju.


@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);
}
}

+ 2
- 1
NemAnCore/Program.cs Переглянути файл

@@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using NemAnBlazor;
using NemAnBlazor.Services;
using NemAnBlazor.Services.Interface;
using NemAnBlazor.Services.Interfaces;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
@@ -22,6 +22,7 @@ builder.Services.AddScoped(_ =>
});

builder.Services.AddScoped<ISearchClientService, SearchClientService>();
builder.Services.AddScoped<IAuthClientService, AuthClientService>();

await builder.Build().RunAsync();


+ 33
- 0
NemAnCore/Services/AuthClientService.cs Переглянути файл

@@ -0,0 +1,33 @@
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();
}
}
}

+ 12
- 0
NemAnCore/Services/Interfaces/IAuthClientService.cs Переглянути файл

@@ -0,0 +1,12 @@
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();
}
}

+ 1
- 1
NemAnCore/Services/Interfaces/ISearchClientService.cs Переглянути файл

@@ -1,6 +1,6 @@
using GrpcShared.DTO.Search;

namespace NemAnBlazor.Services.Interface
namespace NemAnBlazor.Services.Interfaces
{
public interface ISearchClientService
{

+ 1
- 1
NemAnCore/Services/SearchClientService.cs Переглянути файл

@@ -1,6 +1,6 @@
using GrpcShared.DTO.Search;
using GrpcShared.Interfaces;
using NemAnBlazor.Services.Interface;
using NemAnBlazor.Services.Interfaces;

namespace NemAnBlazor.Services
{

+ 1
- 0
SpotifyWorker/SpotifyWorker.csproj Переглянути файл

@@ -9,5 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="protobuf-net.Grpc" Version="1.0.171" />
</ItemGroup>
</Project>

+ 1
- 0
gRPCServer/SpotifyService.csproj Переглянути файл

@@ -10,6 +10,7 @@
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.47.0" />
<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.Reflection" Version="1.0.152" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />

Завантаження…
Відмінити
Зберегти