SlideShare a Scribd company logo
xedotnet.org
Andrea Dottor
@dottor
Blazor, lo sapevi che...
Agenda:
• Authentication
• Build reusable UI components
• Javascript Interop
Intro
DEMO
Demo app: Umarell 2.0
OAuth and OIDC as the best option for authentication in Blazor WebAssembly apps
• AddOidcAuthentication
• AddMsalAuthentication
• AddMicrosoftIdentityWebApi
• AddIdentityServerJwt
Authentication
Duende Software might require you to pay a license fee for production use
of Duende Identity Server.
Authentication - Identity Server
Requirements:
• The UI and the backend are one application which are coupled together.
• The WASM client can only use APIs hosted on the same domain.
With cookie authentication, the Blazor application can served (downloaded)
after a successful login.
• We can use [Authorize] on _Host.cshtml page
Cookie authentication
Token-based authentication based on JSON Web Tokens (JWTs) was chosen
over cookie-based authentication for functional and security reasons:
• Using a token-based protocol offers a smaller attack surface area, as the tokens aren't sent in all
requests.
• Server endpoints don't require protection against Cross-Site Request Forgery (CSRF) because the
tokens are sent explicitly.
• Tokens have narrower permissions than cookies.
• Tokens have a short lifetime, one hour by default, which limits the attack window. Tokens can also be
revoked at any time.
• Self-contained JWTs offer guarantees to the client and server about the authentication process.
• Tokens with OAuth and OIDC don't rely on the user agent behaving correctly to ensure that the app
is secure.
• Token-based protocols, such as OAuth and OIDC, allow for authenticating and authorizing hosted
and standalone apps with the same set of security characteristics.
Authentication
DEMO
Blazor apps are built using Razor components, informally known as Blazor
components. A component is a self-contained portion of user interface (UI)
with processing logic to enable dynamic behavior. Components can be
nested, reused, shared among projects, and used in MVC and Razor Pages
apps.
Components
Components can use a singleton service for comunicate.
We can use a state container to maintain the application status:
• It can be a simple class injected as a singleton (Blazor WebAssembly) or
scoped service (Blazor Server)
Use events to notify changes.
Dependency Injection, singleton, event
DEMO
DEMO: MessageBox
To call into JS from .NET, inject the IJSRuntime abstraction and call one of
the following methods:
• IJSRuntime.InvokeAsync
• JSRuntimeExtensions.InvokeAsync
• JSRuntimeExtensions.InvokeVoidAsync
The TValue return type must also be JSON serializable. TValue should match
the .NET type that best maps to the JSON type returned.
A JS Promise is returned for InvokeAsync methods. InvokeAsync unwraps the
Promise and returns the value awaited by the Promise.
You can call JS method only after that the component is rendered.
IJSRuntime
Blazor enables JavaScript (JS) isolation in standard JavaScript modules
(ECMAScript specification).
JS isolation provides the following benefits:
• Imported JS no longer pollutes the global namespace.
• Consumers of a library and components aren't required to import the related JS.
JavaScript isolation, IJSObjectReference
Disposes the IJSObjectReference for garbage collection in
IAsyncDisposable.DisposeAsync.
When the external JS file is supplied by a Razor class library, specify the
module's JS file using its stable static web asset path:
"./_content/{PACKAGE ID}/{SCRIPT PATH AND FILENAME (.js)}"
IJSInProcessObjectReference represents a reference to a JS object whose
functions can be invoked synchronously.
IJSObjectReference, IJSInProcessObjectReference
Blazor WebAssembly components may experience poor performance when
.NET objects are serialized for JavaScript (JS) interop and either of the
following are true:
• A high volume of .NET objects are rapidly serialized. For example, poor
performance may result when JS interop calls are made on the basis of
moving an input device, such as spinning a mouse wheel.
• Large .NET objects or many .NET objects must be serialized for JS interop. For
example, poor performance may result when JS interop calls require
serializing dozens of files.
IJSUnmarshalledObjectReference represents a reference to an JS object
whose functions can be invoked without the overhead of serializing .NET
data.
IJSUnmarshalledObjectReference
IJSUnmarshalledObjectReference
Only use an element reference to mutate the contents of an empty element
that doesn't interact with Blazor.
An ElementReference can't be passed between components because:
• The instance is only guaranteed to exist after the component is rendered,
which is during or after a component's
OnAfterRender/OnAfterRenderAsync method executes.
• An ElementReference is a struct, which can't be passed as a component
parameter.
ElementReference
To invoke a static .NET method from JavaScript (JS), use the JS functions
DotNet.invokeMethod or DotNet.invokeMethodAsync:
• DotNet.invokeMethodAsync('{ASSEMBLY NAME}', '{.NET METHOD ID}', {ARGUMENTS});
• The .NET method must be public, static, and have the [JSInvokable] attribute.
To invoke an instance .NET method from JavaScript (JS):
• Pass the .NET instance by reference to JS by wrapping the instance in a
DotNetObjectReference and calling Create on it.
• Invoke a .NET instance method from JS using invokeMethod or invokeMethodAsync
from the passed DotNetObjectReference. The .NET instance can also be passed as an
argument when invoking other .NET methods from JS.
• Dispose of the DotNetObjectReference.
Call .NET methods from JavaScript
JavaScript (JS) files and other static assets aren't generally cached on clients
during development in the Development environment.
During development, static asset requests include the Cache-Control
header with a value of no-cache or max-age with a value of zero (0).
During production in the Production environment, JS files are usually cached
by clients.
Cached JavaScript files
DEMO
DEMO: JavaScript interop
• Ability to run multiple Blazor server / Web assembly apps in the same document
• Empty Blazor project template
• Real multithreading (on supported browsers)
• Pause and resume Blazor applications
• More control over circuits lifetime (ability to monitor circuit activity and terminate
from client/server)
• Server-side Blazor: Provide APIs/Extension Points for Circuit Eviction
• Improve prerendering and authentication experience in Blazor
What's new in .NET 7
What's new in .NET 7
https://github.com/dotnet/aspnetcore/issues/39504
Blazor: After finishing Blazor Hybrid support for .NET MAUI, WPF, and
Windows Forms, we’ll make broad improvements to Blazor including:
• New .NET WebAssembly capabilities: mixed-mode AOT, multithreading,
web crypto.
• Enhanced Hot Reload support.
• Data binding improvements.
• More flexible prerendering.
• More control over the lifecycle of Blazor Server circuits.
• Improved support for micro frontends.
ASP.NET Core updates in .NET 7 Preview 1
Riferimenti
• Call JavaScript functions from .NET methods in ASP.NET Core Blazor
• https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet
• Call .NET methods from JavaScript functions in ASP.NET Core Blazor
• https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-dotnet-from-javascript
• ASP.NET Community Standup - Blazor .NET 7 Roadmap
• https://www.youtube.com/watch?v=3o91I6lD-Bo
• What's Coming for Blazor Hybrid in .NET 7
• https://visualstudiomagazine.com/articles/2022/02/10/blazor-hybrid-net-7.aspx
• ASP.NET Core Roadmap for .NET 7 #39504
• https://github.com/dotnet/aspnetcore/issues/39504
• Secure a Blazor WebAssembly application with cookie authentication
• https://guidnew.com/en/blog/secure-a-blazor-webassembly-application-with-cookie-authentication/
• Securing Blazor Web assembly using cookies
• https://damienbod.com/2021/03/08/securing-blazor-web-assembly-using-cookies/
• ASP.NET Core Roadmap for .NET 7 #39504
• https://github.com/dotnet/aspnetcore/issues/39504
Riferimenti
www.dottor.net
andrea@dottor.net
@dottor
Andrea Dottor
Microsoft MVP Developer Technologies
Contatti
Podcast ".NET in Pillole"
DEV.is.it

More Related Content

What's hot

Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
VMware Tanzu
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
Anil Allewar
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
Maurice De Beijer [MVP]
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
Rafal Gancarz
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDB
Valeri Karpov
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
Maurice De Beijer [MVP]
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
QAware GmbH
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
ravisankar munusamy
 
NuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LDNuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LD
Jeff Handley
 
Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019
graemerocher
 
Node js
Node jsNode js
Node js
umesh patil
 
Owin and Katana
Owin and KatanaOwin and Katana
Owin and Katana
Ugo Lattanzi
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
GlobalLogic Ukraine
 
ASP.NET: Present and future
ASP.NET: Present and futureASP.NET: Present and future
ASP.NET: Present and future
Hrvoje Hudoletnjak
 
Andrea Di Persio
Andrea Di PersioAndrea Di Persio
Andrea Di Persio
CodeFest
 
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
Will Huang
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1
Bhavin Shah
 
Node.js quick intro
Node.js quick introNode.js quick intro
Node.js quick intro
Aleksandr Tsertkov
 

What's hot (20)

Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
Winning the Lottery with Spring: A Microservices Case Study for the Dutch Lot...
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDB
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
NuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LDNuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LD
 
Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019Micronaut Deep Dive - Devnexus 2019
Micronaut Deep Dive - Devnexus 2019
 
Node js
Node jsNode js
Node js
 
Owin and Katana
Owin and KatanaOwin and Katana
Owin and Katana
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
 
ASP.NET: Present and future
ASP.NET: Present and futureASP.NET: Present and future
ASP.NET: Present and future
 
Andrea Di Persio
Andrea Di PersioAndrea Di Persio
Andrea Di Persio
 
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
 
Node Session - 1
Node Session - 1Node Session - 1
Node Session - 1
 
Node.js quick intro
Node.js quick introNode.js quick intro
Node.js quick intro
 

Similar to Blazor, lo sapevi che...

Azure serverless architectures
Azure serverless architecturesAzure serverless architectures
Azure serverless architectures
Benoit Le Pichon
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
Sujit Kumar
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
Hitesh-Java
 
CMPE282_009994036_PROJECT_REPORT
CMPE282_009994036_PROJECT_REPORTCMPE282_009994036_PROJECT_REPORT
CMPE282_009994036_PROJECT_REPORT
Sandyarathi Das
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applications
Manish Corriea
 
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
VMworld
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
PawanMM
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
Ansley Rodrigues
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
vipin kumar
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
Buu Nguyen
 
Chinnasamy Manickam
Chinnasamy ManickamChinnasamy Manickam
Chinnasamy Manickam
Chinnasamy Manickam
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
Atlassian
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & Development
GlobalLogic Ukraine
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
Anindita Bhattacharya
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
Omkarsoft Bangalore
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
ADEEBANADEEM
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
Senthil Kumar
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
Eamonn Boyle
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
Synapseindiappsdevelopment
 

Similar to Blazor, lo sapevi che... (20)

Azure serverless architectures
Azure serverless architecturesAzure serverless architectures
Azure serverless architectures
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
CMPE282_009994036_PROJECT_REPORT
CMPE282_009994036_PROJECT_REPORTCMPE282_009994036_PROJECT_REPORT
CMPE282_009994036_PROJECT_REPORT
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applications
 
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
VMworld 2013: vSphere UI Platform Best Practices: Putting the Web Client SDK ...
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
Chinnasamy Manickam
Chinnasamy ManickamChinnasamy Manickam
Chinnasamy Manickam
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & Development
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
 

More from Andrea Dottor

Blazor ♥️ JavaScript
Blazor ♥️ JavaScriptBlazor ♥️ JavaScript
Blazor ♥️ JavaScript
Andrea Dottor
 
Dal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developersDal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developers
Andrea Dottor
 
Blazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web FormBlazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web Form
Andrea Dottor
 
Blazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi realiBlazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi reali
Andrea Dottor
 
What's New in ASP.NET Core 3
What's New in ASP.NET Core 3What's New in ASP.NET Core 3
What's New in ASP.NET Core 3
Andrea Dottor
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
Andrea Dottor
 
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Andrea Dottor
 
Real case: migrate from Web Forms to ASP.NET Core gradually
Real case: migrate from Web Forms to ASP.NET Core graduallyReal case: migrate from Web Forms to ASP.NET Core gradually
Real case: migrate from Web Forms to ASP.NET Core gradually
Andrea Dottor
 
ASP.NET Core - Razor Pages
ASP.NET Core - Razor PagesASP.NET Core - Razor Pages
ASP.NET Core - Razor Pages
Andrea Dottor
 
ASP.NET Core - dove siamo arrivati
ASP.NET Core - dove siamo arrivatiASP.NET Core - dove siamo arrivati
ASP.NET Core - dove siamo arrivati
Andrea Dottor
 
Dependency injection questa sconosciuta
Dependency injection questa sconosciutaDependency injection questa sconosciuta
Dependency injection questa sconosciuta
Andrea Dottor
 
Customize ASP.NET Core scaffolding
Customize ASP.NET Core scaffoldingCustomize ASP.NET Core scaffolding
Customize ASP.NET Core scaffolding
Andrea Dottor
 
ASP.NET, ottimizziamo con la cache
ASP.NET, ottimizziamo con la cacheASP.NET, ottimizziamo con la cache
ASP.NET, ottimizziamo con la cache
Andrea Dottor
 
Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0
Andrea Dottor
 
Creare API pubbliche, come evitare gli errori comuni
 Creare API pubbliche, come evitare gli errori comuni Creare API pubbliche, come evitare gli errori comuni
Creare API pubbliche, come evitare gli errori comuni
Andrea Dottor
 
Deploy & Run on Azure App Service
Deploy & Run on Azure App ServiceDeploy & Run on Azure App Service
Deploy & Run on Azure App Service
Andrea Dottor
 
ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
Andrea Dottor
 
L'evoluzione del web
L'evoluzione del webL'evoluzione del web
L'evoluzione del web
Andrea Dottor
 
Introduzione ad ASP.NET Core
Introduzione ad ASP.NET CoreIntroduzione ad ASP.NET Core
Introduzione ad ASP.NET Core
Andrea Dottor
 
Sviluppare Azure Web Apps
Sviluppare Azure Web AppsSviluppare Azure Web Apps
Sviluppare Azure Web Apps
Andrea Dottor
 

More from Andrea Dottor (20)

Blazor ♥️ JavaScript
Blazor ♥️ JavaScriptBlazor ♥️ JavaScript
Blazor ♥️ JavaScript
 
Dal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developersDal RenderFragment ai Generics, tips for Blazor developers
Dal RenderFragment ai Generics, tips for Blazor developers
 
Blazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web FormBlazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web Form
 
Blazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi realiBlazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi reali
 
What's New in ASP.NET Core 3
What's New in ASP.NET Core 3What's New in ASP.NET Core 3
What's New in ASP.NET Core 3
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
 
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
 
Real case: migrate from Web Forms to ASP.NET Core gradually
Real case: migrate from Web Forms to ASP.NET Core graduallyReal case: migrate from Web Forms to ASP.NET Core gradually
Real case: migrate from Web Forms to ASP.NET Core gradually
 
ASP.NET Core - Razor Pages
ASP.NET Core - Razor PagesASP.NET Core - Razor Pages
ASP.NET Core - Razor Pages
 
ASP.NET Core - dove siamo arrivati
ASP.NET Core - dove siamo arrivatiASP.NET Core - dove siamo arrivati
ASP.NET Core - dove siamo arrivati
 
Dependency injection questa sconosciuta
Dependency injection questa sconosciutaDependency injection questa sconosciuta
Dependency injection questa sconosciuta
 
Customize ASP.NET Core scaffolding
Customize ASP.NET Core scaffoldingCustomize ASP.NET Core scaffolding
Customize ASP.NET Core scaffolding
 
ASP.NET, ottimizziamo con la cache
ASP.NET, ottimizziamo con la cacheASP.NET, ottimizziamo con la cache
ASP.NET, ottimizziamo con la cache
 
Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0
 
Creare API pubbliche, come evitare gli errori comuni
 Creare API pubbliche, come evitare gli errori comuni Creare API pubbliche, come evitare gli errori comuni
Creare API pubbliche, come evitare gli errori comuni
 
Deploy & Run on Azure App Service
Deploy & Run on Azure App ServiceDeploy & Run on Azure App Service
Deploy & Run on Azure App Service
 
ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
 
L'evoluzione del web
L'evoluzione del webL'evoluzione del web
L'evoluzione del web
 
Introduzione ad ASP.NET Core
Introduzione ad ASP.NET CoreIntroduzione ad ASP.NET Core
Introduzione ad ASP.NET Core
 
Sviluppare Azure Web Apps
Sviluppare Azure Web AppsSviluppare Azure Web Apps
Sviluppare Azure Web Apps
 

Recently uploaded

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 

Recently uploaded (20)

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 

Blazor, lo sapevi che...

  • 2. Agenda: • Authentication • Build reusable UI components • Javascript Interop Intro
  • 4. OAuth and OIDC as the best option for authentication in Blazor WebAssembly apps • AddOidcAuthentication • AddMsalAuthentication • AddMicrosoftIdentityWebApi • AddIdentityServerJwt Authentication
  • 5. Duende Software might require you to pay a license fee for production use of Duende Identity Server. Authentication - Identity Server
  • 6. Requirements: • The UI and the backend are one application which are coupled together. • The WASM client can only use APIs hosted on the same domain. With cookie authentication, the Blazor application can served (downloaded) after a successful login. • We can use [Authorize] on _Host.cshtml page Cookie authentication
  • 7. Token-based authentication based on JSON Web Tokens (JWTs) was chosen over cookie-based authentication for functional and security reasons: • Using a token-based protocol offers a smaller attack surface area, as the tokens aren't sent in all requests. • Server endpoints don't require protection against Cross-Site Request Forgery (CSRF) because the tokens are sent explicitly. • Tokens have narrower permissions than cookies. • Tokens have a short lifetime, one hour by default, which limits the attack window. Tokens can also be revoked at any time. • Self-contained JWTs offer guarantees to the client and server about the authentication process. • Tokens with OAuth and OIDC don't rely on the user agent behaving correctly to ensure that the app is secure. • Token-based protocols, such as OAuth and OIDC, allow for authenticating and authorizing hosted and standalone apps with the same set of security characteristics. Authentication
  • 9. Blazor apps are built using Razor components, informally known as Blazor components. A component is a self-contained portion of user interface (UI) with processing logic to enable dynamic behavior. Components can be nested, reused, shared among projects, and used in MVC and Razor Pages apps. Components
  • 10. Components can use a singleton service for comunicate. We can use a state container to maintain the application status: • It can be a simple class injected as a singleton (Blazor WebAssembly) or scoped service (Blazor Server) Use events to notify changes. Dependency Injection, singleton, event
  • 12. To call into JS from .NET, inject the IJSRuntime abstraction and call one of the following methods: • IJSRuntime.InvokeAsync • JSRuntimeExtensions.InvokeAsync • JSRuntimeExtensions.InvokeVoidAsync The TValue return type must also be JSON serializable. TValue should match the .NET type that best maps to the JSON type returned. A JS Promise is returned for InvokeAsync methods. InvokeAsync unwraps the Promise and returns the value awaited by the Promise. You can call JS method only after that the component is rendered. IJSRuntime
  • 13. Blazor enables JavaScript (JS) isolation in standard JavaScript modules (ECMAScript specification). JS isolation provides the following benefits: • Imported JS no longer pollutes the global namespace. • Consumers of a library and components aren't required to import the related JS. JavaScript isolation, IJSObjectReference
  • 14. Disposes the IJSObjectReference for garbage collection in IAsyncDisposable.DisposeAsync. When the external JS file is supplied by a Razor class library, specify the module's JS file using its stable static web asset path: "./_content/{PACKAGE ID}/{SCRIPT PATH AND FILENAME (.js)}" IJSInProcessObjectReference represents a reference to a JS object whose functions can be invoked synchronously. IJSObjectReference, IJSInProcessObjectReference
  • 15. Blazor WebAssembly components may experience poor performance when .NET objects are serialized for JavaScript (JS) interop and either of the following are true: • A high volume of .NET objects are rapidly serialized. For example, poor performance may result when JS interop calls are made on the basis of moving an input device, such as spinning a mouse wheel. • Large .NET objects or many .NET objects must be serialized for JS interop. For example, poor performance may result when JS interop calls require serializing dozens of files. IJSUnmarshalledObjectReference represents a reference to an JS object whose functions can be invoked without the overhead of serializing .NET data. IJSUnmarshalledObjectReference
  • 17. Only use an element reference to mutate the contents of an empty element that doesn't interact with Blazor. An ElementReference can't be passed between components because: • The instance is only guaranteed to exist after the component is rendered, which is during or after a component's OnAfterRender/OnAfterRenderAsync method executes. • An ElementReference is a struct, which can't be passed as a component parameter. ElementReference
  • 18. To invoke a static .NET method from JavaScript (JS), use the JS functions DotNet.invokeMethod or DotNet.invokeMethodAsync: • DotNet.invokeMethodAsync('{ASSEMBLY NAME}', '{.NET METHOD ID}', {ARGUMENTS}); • The .NET method must be public, static, and have the [JSInvokable] attribute. To invoke an instance .NET method from JavaScript (JS): • Pass the .NET instance by reference to JS by wrapping the instance in a DotNetObjectReference and calling Create on it. • Invoke a .NET instance method from JS using invokeMethod or invokeMethodAsync from the passed DotNetObjectReference. The .NET instance can also be passed as an argument when invoking other .NET methods from JS. • Dispose of the DotNetObjectReference. Call .NET methods from JavaScript
  • 19. JavaScript (JS) files and other static assets aren't generally cached on clients during development in the Development environment. During development, static asset requests include the Cache-Control header with a value of no-cache or max-age with a value of zero (0). During production in the Production environment, JS files are usually cached by clients. Cached JavaScript files
  • 21. • Ability to run multiple Blazor server / Web assembly apps in the same document • Empty Blazor project template • Real multithreading (on supported browsers) • Pause and resume Blazor applications • More control over circuits lifetime (ability to monitor circuit activity and terminate from client/server) • Server-side Blazor: Provide APIs/Extension Points for Circuit Eviction • Improve prerendering and authentication experience in Blazor What's new in .NET 7
  • 22. What's new in .NET 7 https://github.com/dotnet/aspnetcore/issues/39504
  • 23. Blazor: After finishing Blazor Hybrid support for .NET MAUI, WPF, and Windows Forms, we’ll make broad improvements to Blazor including: • New .NET WebAssembly capabilities: mixed-mode AOT, multithreading, web crypto. • Enhanced Hot Reload support. • Data binding improvements. • More flexible prerendering. • More control over the lifecycle of Blazor Server circuits. • Improved support for micro frontends. ASP.NET Core updates in .NET 7 Preview 1
  • 24. Riferimenti • Call JavaScript functions from .NET methods in ASP.NET Core Blazor • https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet • Call .NET methods from JavaScript functions in ASP.NET Core Blazor • https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-dotnet-from-javascript • ASP.NET Community Standup - Blazor .NET 7 Roadmap • https://www.youtube.com/watch?v=3o91I6lD-Bo • What's Coming for Blazor Hybrid in .NET 7 • https://visualstudiomagazine.com/articles/2022/02/10/blazor-hybrid-net-7.aspx • ASP.NET Core Roadmap for .NET 7 #39504 • https://github.com/dotnet/aspnetcore/issues/39504
  • 25. • Secure a Blazor WebAssembly application with cookie authentication • https://guidnew.com/en/blog/secure-a-blazor-webassembly-application-with-cookie-authentication/ • Securing Blazor Web assembly using cookies • https://damienbod.com/2021/03/08/securing-blazor-web-assembly-using-cookies/ • ASP.NET Core Roadmap for .NET 7 #39504 • https://github.com/dotnet/aspnetcore/issues/39504 Riferimenti
  • 27. Podcast ".NET in Pillole"