Skip to main content

# Server-side

AuthZ& AuthN

    builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(o =>
        {
            o.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateAudience = false,
                ValidateIssuer = false,
                ValidateActor = false,
                ValidateLifetime = false,
                IssuerSigningKey = JwtHelper.SecurityKey,
            };
        });

    builder.Services.AddAuthorization(o =>
    {
        o.AddPolicy(JwtBearerDefaults.AuthenticationScheme, p =>
        {

            p.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme);
            p.RequireClaim(ClaimTypes.Name);
        });
    });

# Client-side

Title

    builder.Services.AddGrpcClient<SpeakerServiceDefinition.SpeakerServiceDefinitionClient>
        (o => { o.Address = speakers; })
         .ConfigureChannel(o =>
         {

             // o.Credentials
         }).AddCallCredentials((context, metadata) =>
         {
             var token = JwtHelper.GenerateJwtToken("MVC");
             if (!string.IsNullOrEmpty(token))
             {
                 metadata.Add("Authorization", $"Bearer {token}");
             }
             return Task.CompletedTask;
         })