Skip to content

Instantly share code, notes, and snippets.

View cheoalfredo's full-sized avatar
🔖
Learning Vue!!

El profe cheoalfredo

🔖
Learning Vue!!
View GitHub Profile
@cheoalfredo
cheoalfredo / Program.cs
Last active November 10, 2020 22:05
C# Cliente gRPC
using Grpc.Net.Client;
using System.Threading.Tasks;
using MyServer;
namespace MyClient
{
class Program
{
static async Task Main(string[] args)
{
@cheoalfredo
cheoalfredo / OperacionService.cs
Created November 10, 2020 22:07
C# gRPC Server
using System.Threading.Tasks;
using Grpc.Core;
namespace MyServer
{
public class OperacionService : OperacionMatematica.OperacionMatematicaBase
{
public override Task<DivisionResponse> Divide(DivisionRequest request, ServerCallContext context)
{
var result = new DivisionResponse();
@cheoalfredo
cheoalfredo / Test.proto
Created November 10, 2020 22:10
archivo .proto para gRPC
syntax = "proto3";
option csharp_namespace = "MyServer";
package greet;
service OperacionMatematica {
rpc Divide (DivisionRequest) returns (DivisionResponse);
}
message DivisionRequest {
int32 dividendo = 1;
int32 divisor = 2;
}
@cheoalfredo
cheoalfredo / Startup.cs
Created November 10, 2020 22:16
Método Configure(IApplicationBiulder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<OperacionService>();
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
});
@cheoalfredo
cheoalfredo / Program.cs
Last active November 18, 2020 12:27
api simple con top level statement
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using System.IO;
using System.Text;
await Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => {
@cheoalfredo
cheoalfredo / Program.cs
Created November 17, 2020 22:51
El micro empezado sin cambios
using System;
namespace MiniMicro
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
@cheoalfredo
cheoalfredo / Startup.cs
Last active January 14, 2022 21:43
Añadiendo soporte para autenticacion contra keycloak(o en su defecto cualquier proveedor oauth/oidc)
builder.Services.AddAuthorization();
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(o =>
{
o.RequireHttpsMetadata = false;
o.Authority = config.GetValue<string>("Jwt:Authority");
o.Audience = config.GetValue<string>("Jwt:Audience");
@cheoalfredo
cheoalfredo / appsettings.json
Last active February 2, 2021 01:20
seccion para configuracion de Keycloak
"Jwt" : {
"Authority" : "http://localhost:8080/auth/realms/iam",
"Audience": "webapp"
}
@cheoalfredo
cheoalfredo / Startup.cs
Last active January 14, 2022 21:44
Añadir autenticacion al middleware
app.UseAuthentication();
app.UseAuthorization();
@cheoalfredo
cheoalfredo / NumeroController.cs
Last active January 14, 2022 21:44
Controlador de prueba con autorizacion habilitada
app.MapGet("/api/numero", [Authorize]() => {
var rng = new Random();
int[] Numeros = Enumerable.Range(0, 100).ToArray<int>();
return Enumerable.Range(1, 5).Select(index =>
{
var pos = rng.Next(1, Numeros.Length);
return Numeros[pos];
}).ToArray();
});