Skip to content

Commit

Permalink
feat(user-storage): added plugins and half implementations for author…
Browse files Browse the repository at this point in the history
…ization and authentication
  • Loading branch information
EchoSkorJjj committed Feb 18, 2024
1 parent 506440d commit 9e18b43
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 530 deletions.
2 changes: 1 addition & 1 deletion client/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -----------------------------------------------
VITE_TELEGRAM_BOT_API_KEY = ''
VITE_GOOGLE_MAP_API_KEY=""
VITE_GOOGLE_CLIENT_ID=563635941658-naqb6b9b021fqsqesdrfqds3dgbrap35.apps.googleusercontent.com
VITE_GOOGLE_CLIENT_ID=732452164989-t5obdqk38155erts9be9u6rg0fik7ptk.apps.googleusercontent.com
VITE_LOCATIONIQ_ACCESS_TOKEN=""
VITE_STORAGE_KEY=helloworld
VITE_API_BASE_URL=http://localhost:8000
15 changes: 10 additions & 5 deletions client/src/features/auth/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ const useProvideAuth = (): AuthContextType => {

// Handle the response using the provided function
const data = await handleResponse(response);
console.log(data);
const userData = JSON.parse(data.payload.value);
console.log(userData);
login(data.user);
navigate("/dashboard");
navigate("/");
} catch (error) {
console.log(error);
}
Expand All @@ -57,9 +58,13 @@ const useProvideAuth = (): AuthContextType => {
flow: "auth-code",
});

const userStorageTest = async (): Promise<void> => {
const appleAuth = async (): Promise<void> => {
try {
const response = await api.get("/api/v1/user/test?message=neilgae");
const code = "neil";
const response = await api.post("/api/v1/auth/apple/callback", {
code,
});

console.log(response.data.message);
} catch (error) {
console.log(error);
Expand All @@ -82,7 +87,7 @@ const useProvideAuth = (): AuthContextType => {
isAuthenticated,
user,
googleAuth,
userStorageTest,
appleAuth,
signOut,
};
};
5 changes: 4 additions & 1 deletion client/src/pages/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { Box, Button } from "@chakra-ui/react";
import { useAuth } from "~features/auth";

const TestPage = () => {
const { userStorageTest } = useAuth();
const { userStorageTest, googleAuth } = useAuth();
return (
<Box>
<Button colorScheme="blue" onClick={userStorageTest}>
Hit userstorage endpoint
</Button>
<Button colorScheme="blue" onClick={googleAuth}>
Google Auth
</Button>
</Box>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/shared/types/auth/AuthContextType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export type AuthContextType = {
isAuthenticated: boolean;
user: UserData | null;
googleAuth: () => void;
userStorageTest: () => void;
appleAuth: () => void;
signOut: () => void;
};
8 changes: 7 additions & 1 deletion kong-gateway/authn-kong/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ local claim_spec = {
-- Access phase handler
function MyAuthHandler:access(conf)
local path = kong.request.get_path()
local publicPaths = conf.public_paths;

kong.log.notice("The path is ", path)


for i, pub_path in ipairs(publicPaths) do
if pub_path == path then
return
end
end
end

-- Return the handler
Expand Down
10 changes: 8 additions & 2 deletions kong-gateway/authn-kong/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ return {
{ config = {
type = "record",
fields = {
-- Dummy field
{ enabled = { type = "boolean", default = true, required = false } },
{
public_paths = {
type = "array",
default = {},
required = false,
elements = { type = "string" },
}
},
},
},
},
Expand Down
15 changes: 14 additions & 1 deletion kong-gateway/kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
- http
paths:
- /api/v1/user
- /api/v1/auth
plugins:
- name: grpc-gateway
config:
Expand Down Expand Up @@ -46,7 +47,19 @@ plugins:
max_age: 3600
preflight_continue: false

- name: correlation-id
config:
header_name: Kong-Request-ID
generator: tracker
echo_downstream: false

- name: rate-limiting
config:
minute: 100
policy: local
policy: local

- name: authn-kong
config:
public_paths:
- /api/v1/auth/google/callback
- /api/v1/auth/apple/callback
41 changes: 10 additions & 31 deletions kong-gateway/protos/user_storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,12 @@ import "google/protobuf/any.proto";
message ResponseMetadata {
string request_id = 1;
google.protobuf.Timestamp timestamp = 2;
bool success = 3;
string error_message = 4; // Simplified error handling
}

// Custom error response
message ErrorResponse {
int32 code = 1;
string message = 2;
}

// General response wrapper for all service responses
message ServiceResponseWrapper {
ResponseMetadata metadata = 1;
oneof result {
google.protobuf.Any payload = 2; // Flexible payload using Any
ErrorResponse error = 3; // Error details
}
}
message TestRequest {
string message = 1;
}

message TestResponse {
string message = 1;
google.protobuf.Any payload = 2; // Flexible payload using Any
}

// Simplified User definition for demonstration
Expand All @@ -47,23 +29,19 @@ message User {

// Request and response messages
message AuthRequest {
string request_id = 1;
string google_oauth_code = 2;
string code = 1;
}

message GetUserRequest {
string request_id = 1;
string user_id = 2;
string user_id = 1;
}

message UpdateUserRequest {
string request_id = 1;
User user = 2; // Using User message for updates
User user = 1; // Using User message for updates
}

message DeleteUserRequest {
string request_id = 1;
string user_id = 2;
string user_id = 1;
}

message HealthCheckRequest {
Expand All @@ -75,15 +53,16 @@ message HealthCheckResponse {
}

service UserStorage {
rpc Test(TestRequest) returns (TestResponse) {
rpc GoogleAuth(AuthRequest) returns (ServiceResponseWrapper) {
option (google.api.http) = {
get: "/api/v1/user/test"
post: "/api/v1/auth/google/callback"
body: "*"
};
}

rpc Authenticate(AuthRequest) returns (ServiceResponseWrapper) {
rpc AppleAuth(AuthRequest) returns (ServiceResponseWrapper) {
option (google.api.http) = {
post: "/api/v1/user/auth"
post: "/api/v1/auth/apple/callback"
body: "*"
};
}
Expand Down
Loading

0 comments on commit 9e18b43

Please sign in to comment.