"use strict";(self.webpackChunkgrpc_workshop_doc=self.webpackChunkgrpc_workshop_doc||[]).push([[1026],{3905:(e,r,t)=>{t.d(r,{Zo:()=>u,kt:()=>f});var n=t(7294);function i(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function a(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?a(Object(t),!0).forEach((function(r){i(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):a(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function s(e,r){if(null==e)return{};var t,n,i=function(e,r){if(null==e)return{};var t,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||(i[t]=e[t]);return i}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)t=a[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}var c=n.createContext({}),l=function(e){var r=n.useContext(c),t=r;return e&&(t="function"==typeof e?e(r):o(o({},r),e)),t},u=function(e){var r=l(e.components);return n.createElement(c.Provider,{value:r},e.children)},d="mdxType",p={inlineCode:"code",wrapper:function(e){var r=e.children;return n.createElement(n.Fragment,{},r)}},m=n.forwardRef((function(e,r){var t=e.components,i=e.mdxType,a=e.originalType,c=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=l(t),m=i,f=d["".concat(c,".").concat(m)]||d[m]||p[m]||a;return t?n.createElement(f,o(o({ref:r},u),{},{components:t})):n.createElement(f,o({ref:r},u))}));function f(e,r){var t=arguments,i=r&&r.mdxType;if("string"==typeof e||i){var a=t.length,o=new Array(a);o[0]=m;var s={};for(var c in r)hasOwnProperty.call(r,c)&&(s[c]=r[c]);s.originalType=e,s[d]="string"==typeof e?e:i,o[1]=s;for(var l=2;l<a;l++)o[l]=t[l];return n.createElement.apply(null,o)}return n.createElement.apply(null,t)}m.displayName="MDXCreateElement"},963:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var n=t(7462),i=(t(7294),t(3905));const a={},o="Server-side",s={unversionedId:"Day 2/Securing gRPC services/server-side",id:"Day 2/Securing gRPC services/server-side",title:"Server-side",description:"",source:"@site/docs/Day 2/03-Securing gRPC services/01-server-side.md",sourceDirName:"Day 2/03-Securing gRPC services",slug:"/Day 2/Securing gRPC services/server-side",permalink:"/docs/Day 2/Securing gRPC services/server-side",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/Day 2/03-Securing gRPC services/01-server-side.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{},sidebar:"day2",previous:{title:"Securing gRPC services",permalink:"/docs/Day 2/Securing gRPC services/"},next:{title:"Compression",permalink:"/docs/Day 2/compression/"}},c={},l=[],u={toc:l},d="wrapper";function p(e){let{components:r,...t}=e;return(0,i.kt)(d,(0,n.Z)({},u,t,{components:r,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"server-side"},"Server-side"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-csharp",metastring:"title='AuthZ& AuthN'",title:"'AuthZ&","AuthN'":!0},"builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)\n    .AddJwtBearer(o =>\n    {\n        o.TokenValidationParameters = new TokenValidationParameters\n        {\n            ValidateAudience = false,\n            ValidateIssuer = false,\n            ValidateActor = false,\n            ValidateLifetime = false,\n            IssuerSigningKey = JwtHelper.SecurityKey,\n        };\n    });\n\nbuilder.Services.AddAuthorization(o =>\n{\n    o.AddPolicy(JwtBearerDefaults.AuthenticationScheme, p =>\n    {\n\n        p.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme);\n        p.RequireClaim(ClaimTypes.Name);\n    });\n});\n")),(0,i.kt)("h1",{id:"client-side"},"Client-side"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-csharp",metastring:"title='Title'",title:"'Title'"},'\nbuilder.Services.AddGrpcClient<SpeakerServiceDefinition.SpeakerServiceDefinitionClient>\n    (o => { o.Address = speakers; })\n     .ConfigureChannel(o =>\n     {\n\n         // o.Credentials\n     }).AddCallCredentials((context, metadata) =>\n     {\n         var token = JwtHelper.GenerateJwtToken("MVC");\n         if (!string.IsNullOrEmpty(token))\n         {\n             metadata.Add("Authorization", $"Bearer {token}");\n         }\n         return Task.CompletedTask;\n     })\n\n\n')))}p.isMDXComponent=!0}}]);