Skip to content

Commit

Permalink
fix intra login
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusVinix committed Oct 19, 2023
1 parent d54fd64 commit 797538a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ The project its about recreate the famous pong game, using new tools, such as Re
./.production.env

ACCESS_TOKEN_URI="https://api.intra.42.fr/oauth/token"
CLIENT_ID={Intra client id}
CLIENT_SECRET={Intra secret id}
CLIENT_ID_INTRA={Intra client id}
CLIENT_SECRET_INTRA={Intra secret id}
REDIRECT_URI="http://localhost:8080/oauth"
URL_ME="https://api.intra.42.fr/v2/me"
PORT="3000"
Expand Down Expand Up @@ -136,8 +136,8 @@ O projeto se trata de recriar o famoso jogo pong, utilizando de ferramentas mais
./.production.env

ACCESS_TOKEN_URI="https://api.intra.42.fr/oauth/token"
CLIENT_ID={Sua chave na intra}
CLIENT_SECRET={Seu token na intra}
CLIENT_ID_INTRA={Sua chave na intra}
CLIENT_SECRET_INTRA={Seu token na intra}
REDIRECT_URI="http://localhost:8080/oauth"
URL_ME="https://api.intra.42.fr/v2/me"
PORT="3000"
Expand All @@ -147,6 +147,10 @@ O projeto se trata de recriar o famoso jogo pong, utilizando de ferramentas mais
API_EMAIL_USER='teste@gmail.com'
API_EMAIL_FROM='Transcendence API <teste@gmail.com>'
API_EMAIL_PASS='teste'
CLIENT_ID='CLIENT_ID'
CLIENT_SECRET='CLIENT_ID'
REFRESH_TOKEN='TOKEn'
EMAIL='email'

JWT_SECRET='jwtsecret'

Expand Down
9 changes: 5 additions & 4 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable linebreak-style */
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
Expand All @@ -24,11 +25,11 @@ import { MailerModule } from '@nestjs-modules/mailer';
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRoot({
type: 'postgres',
host: 'pgsql',
host: process.env['DATABASE_HOST'],
port: 5432,
username: 'pguser',
password: 'pgpassword',
database: 'postgres',
username: process.env['POSTGRES_USER'],
password: process.env['POSTGRES_PASSWORD'],
database: process.env['DATABASE'],
entities: [
User,
Notify,
Expand Down
9 changes: 6 additions & 3 deletions api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable linebreak-style */
import { BadRequestException, Injectable, InternalServerErrorException, Logger, NotFoundException, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { User } from '../user/entities/user.entity';
Expand All @@ -17,6 +18,7 @@ import { ChangePasswordDto } from './dto/ChangePassword.dto';
import { RecoveryPasswordDto } from './dto/RecoveryPassword.dto';
import { MailingService } from 'src/mailing/mailing.service';
import { EmailDto } from 'src/mailing/dto/email.dto';
import { Exception } from 'handlebars';


@Injectable()
Expand All @@ -39,12 +41,13 @@ export class AuthService {
* @returns Access token to get infos from intra.
*/
async getToken(code: string): Promise<AccessTokenResponse> {
const url = `${process.env['ACCESS_TOKEN_URI']}?grant_type=authorization_code&client_id=${process.env['CLIENT_ID']}&client_secret=${process.env['CLIENT_SECRET']}&redirect_uri=${process.env['REDIRECT_URI']}&code=${code}`;
const url = `${process.env['ACCESS_TOKEN_URI']}?grant_type=authorization_code&client_id=${process.env['CLIENT_ID_INTRA']}&client_secret=${process.env['CLIENT_SECRET_INTRA']}&redirect_uri=${process.env['REDIRECT_URI']}&code=${code}`;
return (
await this.httpService.axiosRef.post(url).then((res) => {
return res.data as AccessTokenResponse;
}).catch(() => {
throw new InternalServerErrorException('getToken: Fail to request access token to intra!');
}).catch((err) => {
console.log(err);
throw new Exception('getToken: Fail to request access token to intra!', err);
})
);

Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export default function SignIn() {
<IdentificationCard size={32} />
</ButtonCustom.Icon>
</ButtonCustom.Root>
{/* <a href={import.meta.env.VITE_REDIRECT_LOGIN_URL}>
<a href={import.meta.env.VITE_REDIRECT_LOGIN_URL}>
<ButtonCustom.Root myclassname='signin__button__root'>
<ButtonCustom.Button msg='Login Intra' myclassname='signin__button' />
<ButtonCustom.Icon myclassname='signin__button__icon'>
<img src={logo42} alt='42 logo' />
</ButtonCustom.Icon>
</ButtonCustom.Root>
</a> */}
</a>
</div>
);
} else if (loading) {
Expand Down

0 comments on commit 797538a

Please sign in to comment.