我正在尝试根据我的需要调整示例项目。
我的需求本质上是:
我的步骤 1.按预期工作。然而,在他们登录后,它似乎正在尝试再次重新路由,我得到:
Interaction_in_progress:交互当前正在进行中。在调用交互API之前,请确保本次交互已经完成。有关更多信息,请访问:aka.ms/msaljs/browser-errors
70 |
71 | useEffect(() => {
72 | if (!isAuthenticated) {
> 73 | msalInstance.loginRedirect(loginRequest);
| ^ 74 | }
75 | })
76 |
Run Code Online (Sandbox Code Playgroud)
无论是否有条件,它都会执行此操作!isAuthenticated。
的用法useIsAuthenticated来自此文档false,即使用户已经登录,似乎也会进行评估。
这是我到目前为止所拥有的:
import { Configuration, RedirectRequest } from '@azure/msal-browser';
// Config object to be passed to Msal on creation
export const msalConfig: Configuration = {
auth: {
clientId: '<client_id>',
authority: 'https://login.microsoftonline.com/<tenant_id>',
},
};
// Add here scopes …Run Code Online (Sandbox Code Playgroud) 它在本地工作。但是,一旦我将其部署到 firebase 上,它就会出现 nextServer 500 内部错误。
8.1.3
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'ko'],
},
};
Run Code Online (Sandbox Code Playgroud)
_app.tsx
import { appWithTranslation } from 'next-i18next';
const App = ({ Component, pageProps }: AppProps): JSX.Element => {
return (
<Provider store={store}>
<MainWrapper>
<Component {...pageProps} />
</MainWrapper>
</Provider>
);
};
export default appWithTranslation(App);
Run Code Online (Sandbox Code Playgroud)
有关服务器端渲染的代码片段
export const getStaticProps: any = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale, [])),
},
});
Run Code Online (Sandbox Code Playgroud)
export const getServerSideProps: GetServerSideProps = async …Run Code Online (Sandbox Code Playgroud) 我的解决方案中有以下控制器设置:
[Route("api/v{VersionId}/[controller]")]
[ApiController]
[Produces("application/json")]
[Consumes("application/json")]
public class MyBaseController : ControllerBase
{
}
[ApiVersion("1.0")]
[ApiVersion("1.1")]
public class AuthenticationController : MyBaseController
{
private readonly ILoginService _loginService;
public AuthenticationController(ILoginService loginService)
{
_loginService = loginService;
}
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[HttpPost("login")]
public ActionResult<v1.JwtTokenResponse> Login([FromBody] v1.LoginRequest loginRequest)
{
var loginResult = _loginService.Login(loginRequest.Email, loginRequest.Password);
if (loginResult.StatusCode != HttpStatusCode.OK)
{
return StatusCode((int)loginResult.StatusCode);
}
var tokenResponse = new v1.JwtTokenResponse() { Token = loginResult.Token };
return Ok(tokenResponse);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的 API 的两个版本之间,此方法没有任何变化,因此从逻辑上讲,我想在我的文档中显示新版本仍然支持该方法。假设我们有第二个客户控制器,它的逻辑发生了一些变化,因此这就是我们拥有新版本 1.1 的原因,因为语义版本控制指示已添加新内容,但以向后兼容的方式添加。
运行这段代码时,自然一切都会构建得很好。代码是有效的,.net core 允许这种实现,但是,当涉及到 swagger …
我们正在开发一种 API,它允许用户通过许多不同的提供商进行身份验证。单独的提供程序不是问题,但事实证明将它们一起使用是一个挑战。
InvalidOperationException当应用程序启动时,似乎添加 1 个以上的提供者会抛出“方案已经存在:承载”。
下面是ConfigureServices函数来自Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "Value";
options.Audience = "Value";
})
.AddMicrosoftIdentityWebApi(options =>
{
Configuration.Bind("AzureAdB2C", options);
options.TokenValidationParameters.NameClaimType = "name";
},
options => { Configuration.Bind("AzureAdB2C", options); });
services.AddControllers();
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder(
JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser()
.Build();
});
}
Run Code Online (Sandbox Code Playgroud)
我使用 Microsoft 示例对 Azure AD 进行身份验证作为起点。删除AddJwtBearerorAddMicrosoftIdentityWebApi调用工作正常,但我需要为我们的用例配置两个提供程序。
有没有办法在 .NET Core 3.1 或更高版本上做到这一点?
我想在我的 .NET Core 应用程序中实现审核日志记录。就像是
[HttpPost, Auditing]
public dynamic SomeApiAction()
{
// API code here
...
}
Run Code Online (Sandbox Code Playgroud)
该属性应该能够在执行之前和之后拦截 API 调用以便记录。
.net core 中是否有这样的机制作为框架的一部分?我不想使用任何第三方组件。请指教。
我正在使用 Nest 6.2 和 ES 6.6
我有以下运行良好的代码:
var response = elasticClient.Search<PropertyRecord>(s => s
.Query(q => q.Terms(
c => c
.Field(f => f.property_id_orig)
.Terms(listOfPropertyIds) // a list of 20 ids say...
))
.From(0)
.Take(100) // just pull up to a 100...
);
if (!response.IsValid)
throw new Exception(response.ServerError.Error.Reason);
return response.Documents;
Run Code Online (Sandbox Code Playgroud)
但我知道底层查询存在问题,因为索引中的所有文档都会返回。所以我希望能够看到 lambda 表达式生成的原始 Json,这样我就可以看到在 Head 插件或 Fiddler 等中运行的结果。
如果我使用 SearchRequest 对象并将其传递给 Search 方法,我是否能够看到查询 Json?
var request = new SearchRequest
{
// and build equivalent query here
};
Run Code Online (Sandbox Code Playgroud)
我在使用 SearchRequest 方法构建相应的查询时遇到问题,并且找不到合适的示例来说明如何执行此操作。
有人知道吗?
asp.net-core ×2
c# ×2
.net-core ×1
api ×1
audit ×1
azure-ad-b2c ×1
i18next ×1
jwt ×1
nest ×1
next-i18next ×1
next.js ×1
reactjs ×1
redirect ×1
swagger ×1
swagger-ui ×1