Comments (6)
`import { Service } from "typedi";
import { UserStatus, User } from "../entities/User";
import { AppDataSource } from "../config/data-source";
import {
ErrorType, ExtraAccessTokenFields,
GrantIdentifier, OAuthClient, OAuthException,
OAuthUser, OAuthUserIdentifier, OAuthUserRepository
} from "@jmondi/oauth2-server";
import { HttpStatus } from "../helper/response";
@service()
export class UserRepository implements OAuthUserRepository {
userRepository = AppDataSource.getRepository(User);
async getUserByCredentials(email: OAuthUserIdentifier, password?: string, grantType?: GrantIdentifier, client?: OAuthClient): Promise<OAuthUser | undefined> {
const dbUser = await this.userRepository.findOne({
where: { email: email?.toString() },
relations: ['userRoleOrganizations', 'userRoleOrganizations.organization', 'userRoleOrganizations.role']
});
if (!dbUser) {
throw new OAuthException("The username or password is incorrect!!", ErrorType.InvalidRequest, undefined, undefined, HttpStatus.BAD_REQUEST);
}
if (!await dbUser.verify(password)) {
throw new OAuthException("The username or password is incorrect!!", ErrorType.InvalidRequest, undefined, undefined, HttpStatus.BAD_REQUEST);
}
if (dbUser.status != UserStatus.ACTIVE) {
throw new OAuthException(`Your account is not active!!`, ErrorType.InvalidRequest, undefined, undefined, HttpStatus.BAD_REQUEST);
}
return dbUser;
}
}`
from ts-oauth2-server.
Any exceptions thrown from within the getUserByCredentials
are being thrown. Nothing should be swallowing these errors.
https://github.com/jasonraimondi/ts-oauth2-server/blob/main/src/grants/auth_code.grant.ts#L76
https://github.com/jasonraimondi/ts-oauth2-server/blob/main/src/grants/auth_code.grant.ts#L308
https://github.com/jasonraimondi/ts-oauth2-server/blob/main/src/grants/password.grant.ts#L65
I'm going to need something more helpful in order to take action on this one.
from ts-oauth2-server.
from ts-oauth2-server.
I will try to get this working in an example. If you're able to get an example up that would be helpful.
from ts-oauth2-server.
I've added an exception to the inMemoryUserRepository and it looks like it is throwing the correct exception, as expected.
https://github.com/jasonraimondi/ts-oauth2-server/compare/issues/82
You will need to create a replication of this for me so I can see the issue.
from ts-oauth2-server.
Hi, the has been resoved,
i just comments handleExpressError(error, res), and handle response,
it is working now,
thanks you.
const login = async (req: Request, res: Response) => {
try {
const oauthResponse = await authorizationServer.respondToAccessTokenRequest(req);
return handleExpressResponse(res, oauthResponse);
} catch (error) {
return responseStatus(res, HttpStatus.BAD_REQUEST, error.message, error);
// return handleExpressError(error, res);
}
}
router.route("/token").post(login);
from ts-oauth2-server.
Related Issues (20)
- Support for any port when redirectUri is a loopback URI HOT 2
- Support RFC 8693 - Token Exchange HOT 6
- Authorization code grant: wrong code in redirect URL HOT 4
- Support RFC7009 “OAuth 2.0 Token Revocation” HOT 1
- feat: allowed custom grant usage
- Feat Request: Allow Custom Parameters in Authorization Flow (e.g., Audience Parameter) HOT 10
- Support OAuth 2.0 Token Introspection (RFC7662)
- how do i implement consent flow? HOT 1
- Typescript compile error
- Allow `userRepository.extraAccessTokenFields()` to set the `iss` (issuer) claim HOT 1
- Enhancement: support RFC 7009 for token revocation HOT 5
- Review nullability of fields in OAuthToken HOT 2
- Inconsistency: use of `isRevoked()` in the `refresh_token` grant is different from its use in the `auth_code` grant, and is unintuitive HOT 1
- Tests / coverage / maintainability badges look unhealthy HOT 1
- Trouble installing packages for example projects HOT 2
- Error running Prisma/Express example - Client authentication failed: Invalid redirect_uri HOT 2
- aud HOT 3
- how to support multi-tenant? does anyone have a example? HOT 1
- refresh_token grant: Token is not linked to client when tokenCID set to 'name'. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-oauth2-server.