两周前我将项目从 dotNetCore 2.2 升级到 3.0。现在我想向其中添加一个 Web 服务。我正在使用 Visual Studio 2019
但是当我单击Microsoft WCF Web Service Reference Provider时出现此错误
关于 Microsoft WCF Web 服务参考提供程序的建议都与我的错误不同
这是我得到的错误
连接的服务组件 Microsoft WCF Web 服务引用提供程序失败。(HRESULT:0x80131500)项目格式不正确
有人可以建议解决这个问题吗?谢谢
我有一个已经可以正常工作的用户身份验证。用户认证的令牌在一小时内过期。
我想实现另一个单独的身份验证策略,即使用我的 Nestjs API 的第三个 API。第三方 API 有单独的端点,令牌应在 24 小时后过期。API 必须与我的应用保持连接 24 小时。
我不介意使用额外的包来实现这一点。
我还需要创建一个名为thirdParty Guard 的保护,以便仅第三部分API 就可以访问该端点。
这是我的 jwt.strategy.ts
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: process.env.SECRETKEY
});
}
async validate(payload: any, done: VerifiedCallback) {
const user = await this.authService.validateUser(payload);
if (!user) {
return done(
new HttpException('Unauthorised access', HttpStatus.UNAUTHORIZED),
false,
);
}
//return user;
return done(null, user, payload.iat)
}
}
Run Code Online (Sandbox Code Playgroud)
ApiKey.strategy.ts
@Injectable()
export class ApiKeyStrategy extends PassportStrategy(HeaderAPIKeyStrategy) {
constructor(private …Run Code Online (Sandbox Code Playgroud) 我有管理员、超级管理员、用户、版主的角色保护,
\n\n这是其中一名警卫的例子。案件中的一名管理员警卫。它们按我的预期工作,但我无法在控制器中添加多个防护装置
\n\nimport\xc2\xa0{\xc2\xa0Injectable,\xc2\xa0CanActivate,\xc2\xa0ExecutionContext,\xc2\xa0HttpException,\xc2\xa0HttpStatus\xc2\xa0}\xc2\xa0from '@nestjs/common';\n\n@/Injectable()\nexport class AdminGuard implements CanActivate\xc2\xa0{\n constructor()\xc2\xa0{\xc2\xa0}\n\n canActivate(context:\xc2\xa0ExecutionContext)\xc2\xa0{\n const request\xc2\xa0=\xc2\xa0context.switchToHttp().getRequest();\n const user\xc2\xa0=\xc2\xa0request.user;\n\n if\xc2\xa0(user.usertype\xc2\xa0==\xc2\xa0'Admin')\xc2\xa0{\n return true;\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n throw new HttpException('Unauthorized\xc2\xa0access',\xc2\xa0HttpStatus.BAD_REQUEST);\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n}\n\nRun Code Online (Sandbox Code Playgroud)\n\n在我的控制器中,我有这个装饰器
\n\n\xc2\xa0\n@UseGuards(AuthGuard('jwt'),\xc2\xa0AdminGuard)\n\nRun Code Online (Sandbox Code Playgroud)\n\n我希望能够做这样的事情
\n\n@UseGuards(AuthGuard('jwt'),\xc2\xa0AdminGuard, SuperAdminGuard)\n\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\n@UseGuards(AuthGuard('jwt'), [AdminGuard, SuperAdminGuard, UserGuard])\n\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\n\n@UseGuards(AuthGuard('jwt'), AdminGuard || SuperAdminGuard || UserGuard])\n\nRun Code Online (Sandbox Code Playgroud)\n\n上述实现均无效。有更好的方法吗?也许我有什么地方做得不对。我已经检查了文档,但似乎无法使其工作
\n我在我的项目中使用 Axios 来调用一些第三方端点。我似乎不明白错误
Nest can't resolve dependencies of the HttpService (?). Please make sure that the argument
AXIOS_INSTANCE_TOKEN at index [0] is available in the TimeModule context.
Potential solutions:
- If AXIOS_INSTANCE_TOKEN is a provider, is it part of the current TimeModule?
- If AXIOS_INSTANCE_TOKEN is exported from a separate @Module, is that module imported within TimeModule?
@Module({
imports: [ /* the Module containing AXIOS_INSTANCE_TOKEN */ ]
})
Run Code Online (Sandbox Code Playgroud)
这是模块
@Module({
imports: [TerminalModule,],
providers: [TimeService, HttpService],
controllers: [TimeController]
})
export class …Run Code Online (Sandbox Code Playgroud) 如您所见,我已完成注册。现在我想发送电子邮件验证,以便用户确认。因此,一旦用户注册,他/她就会收到一封确认邮件。
如何使用“ListCreateAPIView”发送电子邮件验证?
我需要第三方包吗?
有人可以帮我吗?谢谢
这是我的观点
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
class UserDetail(generics.RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
Run Code Online (Sandbox Code Playgroud)
我的序列化程序.py
class UserSerializer(serializers.ModelSerializer):
email = serializers.EmailField(required=True, validators=[UniqueValidator(queryset=User.objects.all())])
username = serializers.CharField(required=True, validators=[UniqueValidator(queryset=User.objects.all())])
password = serializers.CharField(min_length=8, style={'input_type': 'password', 'placeholder': 'Password'})
def create(self, validated_data):
user = User.objects.create_user(validated_data['username'], validated_data['email'], validated_data['password'])
return user
class Meta:
model = User
fields = ('id', 'username', 'email', 'password')
Run Code Online (Sandbox Code Playgroud) 我似乎无法找到错误的来源,因为使用编译的应用程序Found 0 errors. Watching for file changes.我在 StackOverflow 上看到了类似的解决方案,但似乎没有解决问题
这是堆栈跟踪
internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module './app.controller'
Require stack:
- C:\Users\DELL\Documents\DokunFiles\Nestjs\app\api\dist\src\app.module.js
- C:\Users\DELL\Documents\DokunFiles\Nestjs\app\api\dist\src\main.js
Run Code Online (Sandbox Code Playgroud)
使用下面的appModule,将app控制器正确导入到app模块中
app.module.ts
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
@Module({
imports: [MongooseModule.forRoot(process.env.MONGO_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true
})
, UserModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { …Run Code Online (Sandbox Code Playgroud) 我有一个处理注册、登录和其他一些功能的用户服务。我已经在该应用程序上工作了一段时间,有超过 10 个模块。但我注意到每次我注入另一个服务并尝试使用任何端点时我都会收到此错误错误"Unknown authentication strategy "jwt".错误是:-
Internal Server Error
Response body
{
"statusCode": 500,
"message": "Internal server error"
}
Run Code Online (Sandbox Code Playgroud)
一旦我从用户模块中删除注入的服务,一切都会恢复正常。我一直在尝试解决这个问题,因为我需要在用户模块内使用此服务。
这是 jwt.Strategy.ts
import { Injectable, HttpException, HttpStatus } from "@nestjs/common";
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, ExtractJwt, VerifiedCallback } from "passport-jwt";
import { AuthService } from './auth.service';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: process.env.SECRETKEY
});
}
async validate(payload: any, done: VerifiedCallback) {
const user …Run Code Online (Sandbox Code Playgroud) nestjs ×5
node.js ×4
typescript ×3
angular ×2
passport.js ×2
.net-core ×1
axios ×1
c# ×1
controller ×1
django ×1
email ×1
guard ×1
httprequest ×1
httpservice ×1
module ×1
python ×1
roles ×1
wcf ×1
web-services ×1