Move link-building to the server...
All checks were successful
build-docker-imge / Build the docker container (push) Successful in 28m38s
All checks were successful
build-docker-imge / Build the docker container (push) Successful in 28m38s
This commit is contained in:
8
api/src/functions/oauthStart/oauthStart.scenarios.ts
Normal file
8
api/src/functions/oauthStart/oauthStart.scenarios.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import type { ScenarioData } from '@redwoodjs/testing/api'
|
||||
|
||||
export const standard = defineScenario({
|
||||
// Define the "fixture" to write into your test database here
|
||||
// See guide: https://redwoodjs.com/docs/testing#scenarios
|
||||
})
|
||||
|
||||
export type StandardScenario = ScenarioData<unknown>
|
29
api/src/functions/oauthStart/oauthStart.test.ts
Normal file
29
api/src/functions/oauthStart/oauthStart.test.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { mockHttpEvent, mockContext } from '@redwoodjs/testing/api'
|
||||
|
||||
import { handler } from './oauthStart'
|
||||
|
||||
// Improve this test with help from the Redwood Testing Doc:
|
||||
// https://redwoodjs.com/docs/testing#testing-functions
|
||||
|
||||
describe('oauthStart function', () => {
|
||||
it('Should respond with 200', async () => {
|
||||
const httpEvent = mockHttpEvent({
|
||||
queryStringParameters: {
|
||||
id: '42', // Add parameters here
|
||||
},
|
||||
})
|
||||
|
||||
const response = await handler(httpEvent, mockContext())
|
||||
const { data } = JSON.parse(response.body)
|
||||
|
||||
expect(response.statusCode).toBe(200)
|
||||
expect(data).toBe('oauthStart function')
|
||||
})
|
||||
|
||||
// You can also use scenarios to test your api functions
|
||||
// See guide here: https://redwoodjs.com/docs/testing#scenarios
|
||||
//
|
||||
// scenario('Scenario test', async () => {
|
||||
//
|
||||
// })
|
||||
})
|
41
api/src/functions/oauthStart/oauthStart.ts
Normal file
41
api/src/functions/oauthStart/oauthStart.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import type { APIGatewayEvent, Context } from 'aws-lambda'
|
||||
|
||||
import { logger } from 'src/lib/logger'
|
||||
|
||||
/**
|
||||
* The handler function is your code that processes http request events.
|
||||
* You can use return and throw to send a response or error, respectively.
|
||||
*
|
||||
* Important: When deployed, a custom serverless function is an open API endpoint and
|
||||
* is your responsibility to secure appropriately.
|
||||
*
|
||||
* @see {@link https://redwoodjs.com/docs/serverless-functions#security-considerations|Serverless Function Considerations}
|
||||
* in the RedwoodJS documentation for more information.
|
||||
*
|
||||
* @typedef { import('aws-lambda').APIGatewayEvent } APIGatewayEvent
|
||||
* @typedef { import('aws-lambda').Context } Context
|
||||
* @param { APIGatewayEvent } event - an object which contains information from the invoker.
|
||||
* @param { Context } _context - contains information about the invocation,
|
||||
* function, and execution environment.
|
||||
*/
|
||||
export const handler = async (event: APIGatewayEvent, _context: Context) => {
|
||||
logger.info(`${event.httpMethod} ${event.path}: oauth function`)
|
||||
|
||||
switch (event.path) {
|
||||
case '/oauthStart/microsoft':
|
||||
return await callback()
|
||||
default:
|
||||
return {
|
||||
statusCode: 404,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const callback = async () => {
|
||||
return {
|
||||
statusCode: 302,
|
||||
headers: {
|
||||
Location: `https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${process.env.MICROSOFT_OAUTH_CLIENT_ID}&grant_type=authorization_code&response_type=code&redirect_uri=${process.env.MICROSOFT_OAUTH_REDIRECT_URI}&scope=${process.env.MICROSOFT_OAUTH_SCOPES.split(' ').join('+')}`,
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user