Skip to content

Commit

Permalink
Modified a few things in the client credentials workflow #44
Browse files Browse the repository at this point in the history
  • Loading branch information
raghunandanarava committed Jun 7, 2022
1 parent 42012c7 commit 1e2b88a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/flows/flows.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
import { FlowsController } from './flows.controller';
import { FlowsService } from './flows.service';
import { TokenModule } from '../token/token.module';
import { DiscoveryModule } from 'src/discovery/discovery.module';

@Module({
imports: [TokenModule],
imports: [TokenModule, DiscoveryModule],
controllers: [FlowsController],
providers: [FlowsService],
exports: [FlowsService],
Expand Down
17 changes: 16 additions & 1 deletion src/flows/flows.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { Inject, Injectable } from '@nestjs/common';
import { TokenService } from '../token/token.service';
import { DiscoveryService } from 'src/discovery/discovery.service';

@Injectable()
export class FlowsService {
@Inject(TokenService)
private readonly tokenService: TokenService;

@Inject(DiscoveryService)
private readonly discoveryService: DiscoveryService;

async clientCredentialsFlow(issuer_s: string) {
return await this.tokenService.requestToken(issuer_s);
const issuer = await this.discoveryService.get_issuer(issuer_s);
const receivedToken = await this.tokenService.getToken(
String(issuer.token_endpoint),
{
grant_type: process.env.CLIENT_CREDENTIALS_STRING,
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
audience: process.env.AUDIENCE,
},
);

return receivedToken.data.access_token;
}
}
2 changes: 1 addition & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class UserService {
const result = await this.flowsService.clientCredentialsFlow(
process.env.ISSUER_STRING,
);
return JSON.stringify(result.data);
return JSON.stringify(result);
}
}

0 comments on commit 1e2b88a

Please sign in to comment.