Coder Social home page Coder Social logo

OAuthException throw not supporting in latest version, gettting app crash when throw error from UserRepository about ts-oauth2-server HOT 6 CLOSED

ankush-instinctiq avatar ankush-instinctiq commented on July 21, 2024 1
OAuthException throw not supporting in latest version, gettting app crash when throw error from UserRepository

from ts-oauth2-server.

Comments (6)

ankush-instinctiq avatar ankush-instinctiq commented on July 21, 2024 1

`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.

jasonraimondi avatar jasonraimondi commented on July 21, 2024

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.

ankush-instinctiq avatar ankush-instinctiq commented on July 21, 2024

from ts-oauth2-server.

jasonraimondi avatar jasonraimondi commented on July 21, 2024

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.

jasonraimondi avatar jasonraimondi commented on July 21, 2024

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

 2023-08-24 at 11 43 57 AM

You will need to create a replication of this for me so I can see the issue.

from ts-oauth2-server.

ankush-instinctiq avatar ankush-instinctiq commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.