使用 WebAPI 后端托管的 Blazor 服务器
自从我上次进行任何开发以来,发生了很多变化,所以请耐心等待,
概述
我的知识水平
一直在学习 C# 来协助服务器托管应用程序中的错误查找,在此之前是用于 IRC 机器人的 Java 和 PHP 5.6。 (哦,我只是让自己感觉自己老了)
背景故事
我一直在积累知识并阅读各种教程和 Microsoft 文档(这让我对自己需要什么更加困惑/想要)我想选择一个 RESTful 数据流,如下图所示。
显示从客户端到 Blazor 服务器、RESTful 服务器到数据库并再次返回的关系的数据访问模型
找到教程(示例来自Pragim - 我遵循的是文本,而不是视频),它讨论了 Blazor 服务器级别的 ASP.Net Core Identity。对我来说,将其移动到 RESTful 服务器(我现在了解使用 ASP.Net WebAPI)级别更有意义,因为我希望以后能够开发不同的前端,例如,稍后成为前端 Android 应用程序,并且仍然维护相同的后端用于授权、身份验证和数据管理。
我四处寻找更多教程,发现 使用 WebApi 教程保护客户端 Blazor,但它讨论了 Blazor WebAssembly。太多的信息让我感觉超负荷。
目标
我想提供一个松散耦合的管理系统来帮助我管理我的急救志愿者单位。单位成员将使用该系统来跟踪他们的工作时间,查看和跟踪认证到期时间,各个角色和级别的领导将使用它来查看工作时间报告,以指挥链方式发送通知,以及我认为系统需要的其他功能。类似于员工管理系统。
也有可能从我的本地单位(最多 50 名成员)发展到由 3-5 个单位组成的理事会,并且在全国范围内的可能性很小,因此我需要松散耦合,因为不同级别的技术可能需要更换虽然这超出了当前开发的范围,但范围是学习并为我的单位建立一个工作系统,我觉得需要以一种更容易成长/适应的方式进行设计。
我对 Blazor WebAss 与 Blazor Server 托管的理解是,WebAss 下载所有逻辑,而服务器在服务器端呈现内容,并且仅发送更改,我使用服务器,因为它可以通过以下设备访问:在 4G 等无线接入上,减少带宽和处理使用量是关键。我决定尽可能地使用 ASP.Net、C#。 Blazor 服务器和 Web API 是独立的,但在本地托管。
==============
摘要 TL;DR:
如何使用 Blazor Server Hosted 访问 WebAPI 服务器进行身份验证/授权?通过此设置是否可以允许注册 Google、Microsoft 和 Facebook 等外部服务?
So much has changed since I last did any development so please bear with me,
Overview
My knowledge level
Been picking up C# in assisting bug hunting in a server-hosted application, before this it was Java for IRC bots and PHP 5.6. (Oof, I just made myself feel old)
Backstory
I've been building my knowledge and reading various tutorials and Microsoft Documentation (Which has caused me so much more confusion as to what I need/want) that I want to settle on a RESTful data flow like the image below.
I found tutorials (Example from Pragim - I followed the text, not videos) and it talks about ASP.Net Core Identity on the Blazor Server level. To me, it makes more sense to move it to the RESTful server (Which I now understand use the ASP.Net WebAPI) level, since I want to be able to later develop different front end, for example, a front end Android app later on and still maintain the same backend for authorization, authentication, and data management.
I've looked around for more tutorials and found Securing Client-Side Blazor with WebApi tutorial but it talks about Blazor WebAssembly. I'm feeling overloaded with too much information.
Goal
I want to provide a loosely coupled Management System to help me manage my first responder volunteer unit. Unit members would use the system for tracking their hours, seeing and tracking certification expiry, leadership in various roles and levels would use it to see reports of hours, sending notification in the chain of command way, and other features I feel the system needs. Similar to an employee management system.
There's also a possibility of growing from my local unit of up to 50 members, to a council of 3-5 units, and a rare possibility of nationwide hence my need to be loosely coupled as the tech at different levels may need to be swapped out although that's beyond the scope of current development, the scope is to learn and have a working system for my unit, I feel the need to design in a way that growing/adapting is easier.
My understanding of Blazor WebAss vs Blazor Server hosting is that WebAss download all of the logic, while the Server rendered the content on the server-side and only the change is sent and I went with the server since it could be accessed via devices that are on wireless access like 4G, etc and reducing bandwidth and processing usage is key. I am settled on using ASP.Net, C# as full-stack as I can. Blazor Server and Web API are separate but locally hosted.
==============
Summary TL;DR:
How to use Blazor Server Hosted to access WebAPI server to authenticate/authorize? Is it even possible to allow sign up with external services like Google, Microsoft, and Facebook with this setup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答是是的,您可以在同一个应用程序中调用外部 API,使用 Identity 并且 Identity 已经能够通过 google/ms/fb 进行身份验证。
然而 Blazor 服务器很容易出现延迟(服务器在哪里很重要)并且需要良好的连接。
我会质疑它在这里的位置。
Blazor WebAssembly 是一个客户端 UI 框架,如果您倾向于删除它,因为您的 WebAPI 是独立的,那么以后会更容易。
The short answer is Yes, you can call external API's in the same app, use Identity and Identity already has the ability to authenticate via google/ms/fb.
However Blazor server is prone to latency(it would matter where the server is) and requires a decent connection.
I would question its place here.
Blazor webassembly is a client side UI framework and it would be easier later if you where inclined to removed it as your webapi is separate.