Skip to content

Task 7 aws task - #6

Open
Javlon999 wants to merge 6 commits into
masterfrom
task-7-aws-task
Open

Javlon999 wants to merge 6 commits into
masterfrom
task-7-aws-task

Conversation

@Javlon999

Copy link
Copy Markdown
Owner

Task 7 - Authorization Service with Basic Authorizer Lambda
PR Description:

Task 7 - Authorization Service Implementation

What was done:

This PR implements Basic Authorization for the Import Service API using a Lambda Authorizer.


Task 7.1 - Authorization Service

  • Created basicAuthorizer Lambda function under lambda/basicAuthorizer.ts
  • Created AuthorizationServiceStack in lib/authorization-service-stack.ts
  • Lambda decodes Basic Authorization token (base64) and validates credentials
  • Credentials are stored securely in .env file (not committed to GitHub)
  • Lambda returns:
    • 401 Unauthorized - when Authorization header is not provided
    • 403 Forbidden - when credentials are invalid

Task 7.2 - Import Service Authorization

  • Updated ImportServiceStack to use basicAuthorizer as a Lambda Authorizer
  • Added TokenAuthorizer to the /import GET endpoint in API Gateway
  • Only requests with valid Authorization header can access the endpoint

Task 7.3 - Frontend Update

  • Updated frontend to send Authorization: Basic <token> header with every /import request
  • Frontend reads authorization_token from browser localStorage

How to Test:

Set token in browser localStorage:

localStorage.setItem('authorization_token', btoa('github_username:TEST_PASSWORD'))

// Test 1 - No Auth (401)
fetch('https://mrtfclzte1.execute-api.ap-southeast-2.amazonaws.com/prod/import?name=products.csv', {
  method: 'GET'
}).then(res => console.log('Status:', res.status))

// Test 2 - Wrong credentials (403)
fetch('https://mrtfclzte1.execute-api.ap-southeast-2.amazonaws.com/prod/import?name=products.csv', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic ' + btoa('Javlon999:WRONG_PASSWORD')
  }
}).then(res => console.log('Status:', res.status))

// Test 3 - Correct credentials (200)
fetch('https://mrtfclzte1.execute-api.ap-southeast-2.amazonaws.com/prod/import?name=products.csv', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic ' + btoa('Javlon999:TEST_PASSWORD')
  }
}).then(res => console.log('Status:', res.status))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant