English 中文(简体)
如何限制反应前端和c#后端口的翻版接入?
原标题:How can i restrict api access in a react frontend and c# backend app?
  • 时间:2024-05-06 02:33:31
  •  标签:
  • c#
  • reactjs

I have an app that authenticates a user using MSAL and that is in the client side , react. But on the backend , c# i make api calls and I want to add some Authorization to only allow users who have successfully logged into the app.

How can i do this, is there an example ?

问题回答

如果您是用MSAL.的话,您将获得token/code>。 您可在请求书头上发送<代码>Auth Token<>/code>,在报到服务机上可加以编码和验证。

Here is an example of axios get and post methods which uses Auth Token..

import axios from  axios ;

// in getToken method., write logic to get Auth token using `useMsal` method.
const token = getToken();

axios.get(`/api/your_url`, {
  headers: {
     Authorization : `Bearer ${token}`
  },
})
.then((response) => console.log(response))
.catch((response) => console.log(error));

可在<条码>使用Msal的方法<代码>msal-react上找到。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签