-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1737 from SUNET/eunju-security-zone
Eunju security zone
- Loading branch information
Showing
22 changed files
with
478 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Code and data structures for talking to the Authn backend microservice. | ||
*/ | ||
|
||
import { createAsyncThunk, PayloadAction } from "@reduxjs/toolkit"; | ||
import { EduIDAppDispatch, EduIDAppRootState } from "eduid-init-app"; | ||
import { KeyValues, makeGenericRequest, RequestThunkAPI } from "./common"; | ||
import { GetStatusRequest, GetStatusResponse } from "./eduidEidas"; | ||
|
||
type DispatchWithAuthn = EduIDAppDispatch; | ||
type StateWithAuthn = EduIDAppRootState; | ||
|
||
export interface AuthenticateResponse { | ||
location: string; | ||
} | ||
|
||
export interface AuthenticateRequest { | ||
frontend_action?: string; | ||
} | ||
|
||
/*********************************************************************************************************************/ | ||
/** | ||
* @public | ||
* @function authenticate | ||
* @desc | ||
*/ | ||
export const authenticate = createAsyncThunk< | ||
AuthenticateResponse, // return type | ||
AuthenticateRequest, // args type | ||
{ dispatch: DispatchWithAuthn; state: StateWithAuthn } | ||
>("authn/authenticate", async (args, thunkAPI) => { | ||
const body: KeyValues = args; | ||
return makeAuthnRequest<AuthenticateResponse>(thunkAPI, "authenticate", body) // return type | ||
.then((response) => response.payload) | ||
.catch((err) => thunkAPI.rejectWithValue(err)); | ||
}); | ||
|
||
/*********************************************************************************************************************/ | ||
/** | ||
* @public | ||
* @function authnGetStatus | ||
* @desc Redux async thunk to fetch status for an earlier operation. | ||
*/ | ||
export const authnGetStatus = createAsyncThunk< | ||
GetStatusResponse, // return type | ||
GetStatusRequest, // args type | ||
{ dispatch: DispatchWithAuthn; state: StateWithAuthn } | ||
>("authn/getStatus", async (args, thunkAPI) => { | ||
const body: KeyValues = args; | ||
return makeAuthnRequest<GetStatusResponse>(thunkAPI, "get-status", body) | ||
.then((response) => response.payload) | ||
.catch((err) => thunkAPI.rejectWithValue(err)); | ||
}); | ||
|
||
/*********************************************************************************************************************/ | ||
async function makeAuthnRequest<T>( | ||
thunkAPI: RequestThunkAPI, | ||
endpoint: string, | ||
body?: KeyValues, | ||
data?: KeyValues | ||
): Promise<PayloadAction<T, string, never, boolean>> { | ||
const state = thunkAPI.getState(); | ||
|
||
if (!state.config.authn_service_url) { | ||
throw new Error("Missing configuration state.config.authn_service_url"); | ||
} | ||
|
||
return makeGenericRequest<T>(thunkAPI, state.config.authn_service_url, endpoint, body, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.