Skip to content

Commit

Permalink
fix(auth-service): In authentication service fixed issue current user…
Browse files Browse the repository at this point in the history
… is not bound to any value in the context (#349)
  • Loading branch information
faizan1620 authored Oct 24, 2021
1 parent 501513c commit 85d3fb8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const queryGen = (from: 'body' | 'query') => {

export class AppleLoginController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER)
private readonly user: AuthUser | undefined,
@repository(AuthClientRepository)
public authClientRepository: AuthClientRepository,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
Expand Down Expand Up @@ -114,10 +112,12 @@ export class AppleLoginController {
@inject(RestBindings.Http.RESPONSE) response: Response,
@inject(AuthCodeBindings.CODEWRITER_PROVIDER)
appleCodeWriter: CodeWriterFn,
@inject(AuthenticationBindings.CURRENT_USER)
user: AuthUser | undefined,
): Promise<void> {
const clientId = new URLSearchParams(state).get('client_id');

if (!clientId || !this.user) {
if (!clientId || !user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
const client = await this.authClientRepository.findOne({
Expand All @@ -131,7 +131,7 @@ export class AppleLoginController {
try {
const codePayload: ClientAuthCode<User, typeof User.prototype.id> = {
clientId,
user: this.user,
user: user,
};
const token = await appleCodeWriter(
jwt.sign(codePayload, client.secret, {
Expand All @@ -141,7 +141,7 @@ export class AppleLoginController {
algorithm: 'HS256',
}),
);
const role = this.user.role;
const role = user.role;
response.redirect(
`${process.env.WEBAPP_URL ?? ''}${
client.redirectUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const queryGen = (from: 'body' | 'query') => {

export class FacebookLoginController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER)
private readonly user: AuthUser | undefined,
@repository(AuthClientRepository)
public authClientRepository: AuthClientRepository,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
Expand Down Expand Up @@ -116,9 +114,11 @@ export class FacebookLoginController {
@inject(RestBindings.Http.RESPONSE) response: Response,
@inject(AuthCodeBindings.CODEWRITER_PROVIDER)
facebookCodeWriter: CodeWriterFn,
@inject(AuthenticationBindings.CURRENT_USER)
user: AuthUser | undefined,
): Promise<void> {
const clientId = new URLSearchParams(state).get('client_id');
if (!clientId || !this.user) {
if (!clientId || !user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
const client = await this.authClientRepository.findOne({
Expand All @@ -132,7 +132,7 @@ export class FacebookLoginController {
try {
const codePayload: ClientAuthCode<User, typeof User.prototype.id> = {
clientId,
user: this.user,
user: user,
};
const token = await facebookCodeWriter(
jwt.sign(codePayload, client.secret, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
} from 'loopback4-authentication';
import {authorize} from 'loopback4-authorization';
import {URLSearchParams} from 'url';

import {User} from '../../models';
import {AuthCodeBindings, CodeWriterFn} from '../../providers';
import {AuthClientRepository} from '../../repositories';
Expand All @@ -42,8 +41,6 @@ const queryGen = (from: 'body' | 'query') => {

export class GoogleLoginController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER)
private readonly user: AuthUser | undefined,
@repository(AuthClientRepository)
public authClientRepository: AuthClientRepository,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
Expand Down Expand Up @@ -158,9 +155,11 @@ export class GoogleLoginController {
@inject(RestBindings.Http.RESPONSE) response: Response,
@inject(AuthCodeBindings.CODEWRITER_PROVIDER)
googleCodeWriter: CodeWriterFn,
@inject(AuthenticationBindings.CURRENT_USER)
user: AuthUser | undefined,
): Promise<void> {
const clientId = new URLSearchParams(state).get('client_id');
if (!clientId || !this.user) {
if (!clientId || !user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
const client = await this.authClientRepository.findOne({
Expand All @@ -174,7 +173,7 @@ export class GoogleLoginController {
try {
const codePayload: ClientAuthCode<User, typeof User.prototype.id> = {
clientId,
user: this.user,
user: user,
};
const token = await googleCodeWriter(
jwt.sign(codePayload, client.secret, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const queryGen = (from: 'body' | 'query') => {

export class InstagramLoginController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER)
private readonly user: AuthUser | undefined,
@repository(AuthClientRepository)
public authClientRepository: AuthClientRepository,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
Expand Down Expand Up @@ -116,9 +114,11 @@ export class InstagramLoginController {
@inject(RestBindings.Http.RESPONSE) response: Response,
@inject(AuthCodeBindings.CODEWRITER_PROVIDER)
instgaramCodeWriter: CodeWriterFn,
@inject(AuthenticationBindings.CURRENT_USER)
user: AuthUser | undefined,
): Promise<void> {
const clientId = new URLSearchParams(state).get('client_id');
if (!clientId || !this.user) {
if (!clientId || !user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
const client = await this.authClientRepository.findOne({
Expand All @@ -132,7 +132,7 @@ export class InstagramLoginController {
try {
const codePayload: ClientAuthCode<User, typeof User.prototype.id> = {
clientId,
user: this.user,
user: user,
};
const token = await instgaramCodeWriter(
jwt.sign(codePayload, client.secret, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const queryGen = (from: 'body' | 'query') => {

export class KeycloakLoginController {
constructor(
@inject(AuthenticationBindings.CURRENT_USER)
private readonly user: AuthUser | undefined,
@repository(AuthClientRepository)
public authClientRepository: AuthClientRepository,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
Expand Down Expand Up @@ -159,9 +157,11 @@ export class KeycloakLoginController {
@inject(RestBindings.Http.RESPONSE) response: Response,
@inject(AuthCodeBindings.CODEWRITER_PROVIDER)
keycloackCodeWriter: CodeWriterFn,
@inject(AuthenticationBindings.CURRENT_USER)
user: AuthUser | undefined,
): Promise<void> {
const clientId = new URLSearchParams(state).get('client_id');
if (!clientId || !this.user) {
if (!clientId || !user) {
throw new HttpErrors.Unauthorized(AuthErrorKeys.ClientInvalid);
}
const client = await this.authClientRepository.findOne({
Expand All @@ -175,7 +175,7 @@ export class KeycloakLoginController {
try {
const codePayload: ClientAuthCode<User, typeof User.prototype.id> = {
clientId,
user: this.user,
user:user,
};
const token = await keycloackCodeWriter(
jwt.sign(codePayload, client.secret, {
Expand Down

0 comments on commit 85d3fb8

Please sign in to comment.