Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget sizing #1092

Merged
merged 30 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
17b9534
Fix widget sizing
forgetso Mar 12, 2024
0a1bd3b
remove debug bg colours
forgetso Mar 12, 2024
c5f42ff
Hide overflow
forgetso Mar 12, 2024
fc1e4b1
remove div
forgetso Mar 12, 2024
902e478
Remove debug code
forgetso Mar 12, 2024
eb01575
Update POW package
forgetso Mar 12, 2024
09c454d
Fix widget URL
forgetso Mar 12, 2024
82a3412
Put URL in variable
forgetso Mar 12, 2024
d696c3b
Put widget text in variable
forgetso Mar 12, 2024
d7b1b80
Move logos into their own files
forgetso Mar 12, 2024
f4c42e1
lint:fix
forgetso Mar 12, 2024
cf2e2c8
update deps
forgetso Mar 12, 2024
0a89126
Add sleep to dodgy test
forgetso Mar 12, 2024
bfed250
Fix modal style and widget height
forgetso Mar 12, 2024
2a35715
Update placeholder
forgetso Mar 12, 2024
bcfb297
Update demo with collector env var setup
forgetso Mar 12, 2024
b997b57
update development env template
forgetso Mar 12, 2024
0ac528c
remove unused style
forgetso Mar 12, 2024
762b64c
Fix colour picking
forgetso Mar 12, 2024
14a5227
remove unused ids and classes from logo svgs
forgetso Mar 12, 2024
cedf39b
Add checks for storing events and set env vars in correct places
forgetso Mar 12, 2024
1e9ae2b
Allow custom provider host
forgetso Mar 13, 2024
83d8f30
Add option to override endpoint and contract to bundling
forgetso Mar 13, 2024
5bc7592
Merge branch 'main' into widget-sizing
forgetso Mar 13, 2024
845ea87
Merge branch 'main' into widget-sizing
forgetso Mar 13, 2024
69fe842
Merge branch 'main' into widget-sizing
forgetso Mar 13, 2024
6594376
Address PR comments
forgetso Mar 13, 2024
2bd1929
Address more comments
forgetso Mar 13, 2024
876cdb4
lint:fix
forgetso Mar 13, 2024
66ba0cd
Change export and npm i
forgetso Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,40 @@ data contains the following fields:

## Verify the User Response Server Side

To verify a user's response on the server side, simpy import the `verify` function from `@prosopo/server` and pass it
By adding the client side code, you were able to render a Procaptcha widget that identified if users were real people or
automated bots. When the captcha succeeded, the Procaptcha script inserted unique data into your form data, which is
then sent to your server for verification. The are currently two options for verifying the user's response server side:

### Option 1. API Verification

To verify that the token is indeed real and valid, you must now verify it at the API endpoint:

https://api.prosopo.io/siteverify

The endpoint expects a POST request with two parameters: your account secret and the `procaptcha-response` sent from
your frontend HTML to your backend for verification. You can optionally include the user's IP address as an additional
security check.

A simple test will look like this:

```bash
curl -X POST https://api.prosopo.io/siteverify \
-H "Content-Type: application/json" \
-d 'PROCAPTCHA_RESPONSE'
```

Note that the endpoint expects the application/json Content-Type. You can see exactly what is sent
using

```bash
curl -vv
```

in the example above.

### Option 2. TypeScript Verification Package

To verify a user's response using TypeScript, simpy import the `verify` function from `@prosopo/server` and pass it
the `procaptcha-response` POST data. Types can be imported from `@prosopo/types`.

```typescript
Expand All @@ -141,5 +174,5 @@ if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
}
```

There is an example server side implementation
There is an example TypeScript server side implementation
in [demos/client-example-server](https://github.com/prosopo/captcha/tree/main/demos/client-example-server).
18 changes: 11 additions & 7 deletions demos/client-bundle-example/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
<label>Password</label>
<input type="password" required />
</div>
<div id="procaptcha-container"></div>
<!-- Dev sitekey -->
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
></div>
<div class="mui-textfield mui-textfield--float-label">
<div id="procaptcha-container"></div>
</div>
<div class="mui-textfield mui-textfield--float-label">
<!-- Dev sitekey -->
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
></div>
</div>
<input type="submit" class="mui-btn mui-btn--raised" />
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion demos/client-example/env.development
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ PROSOPO_PORT=9230
PROSOPO_DEFAULT_NETWORK=development
PROSOPO_DEFAULT_ENVIRONMENT=development
PROSOPO_MONGO_EVENTS_URI=mongodb+srv://<MONGO_URI_HERE>/frictionless_events
_DEV_ONLY_WATCH_EVENTS=false
_DEV_ONLY_WATCH_EVENTS=false
45 changes: 24 additions & 21 deletions demos/client-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,31 @@ function App() {
/>
</FormControl>

<Procaptcha
config={config}
callbacks={{ onAccountNotFound, onError, onHuman, onExpired }}
/>

<Box sx={{ p: 1 }}>
<Stack direction="column" spacing={1} sx={{ '& button': { m: 1 } }}>
<Button
variant="contained"
onClick={onActionHandler}
disabled={!procaptchaOutput}
>
{isLogin ? 'Login' : 'Sign up'}
</Button>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box>
<Typography>- or -</Typography>
<FormControl sx={{ m: 1 }}>
<Procaptcha
config={config}
callbacks={{ onAccountNotFound, onError, onHuman, onExpired }}
/>
</FormControl>
<FormControl>
<Box sx={{ p: 1 }}>
<Stack direction="column" spacing={1} sx={{ '& button': { m: 1 } }}>
<Button
variant="contained"
onClick={onActionHandler}
disabled={!procaptchaOutput}
>
{isLogin ? 'Login' : 'Sign up'}
</Button>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Box>
<Typography>- or -</Typography>
</Box>
</Box>
</Box>
<Button onClick={onChangeHandler}>{isLogin ? 'Signup' : 'Login'}</Button>
</Stack>
</Box>
<Button onClick={onChangeHandler}>{isLogin ? 'Signup' : 'Login'}</Button>
</Stack>
</Box>
</FormControl>
</FormGroup>
</form>
</Box>
Expand Down
1 change: 1 addition & 0 deletions demos/client-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default defineConfig(function ({ command, mode }) {
'process.env.PROSOPO_WEB2': JSON.stringify(process.env.PROSOPO_WEB2),
'process.env.PROSOPO_SERVER_URL': JSON.stringify(process.env.PROSOPO_SERVER_URL),
'process.env.PROSOPO_PORT': JSON.stringify(process.env.PROSOPO_PORT),
'process.env._DEV_ONLY_WATCH_EVENTS': JSON.stringify(process.env._DEV_ONLY_WATCH_EVENTS),
}
logger.debug('define', JSON.stringify(define))

Expand Down
10 changes: 2 additions & 8 deletions demos/client-pow-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Prosopo procaptcha client login example" />
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="manifest.json" />

<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
2 changes: 1 addition & 1 deletion demos/client-pow-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function App() {
atlasUri: process.env._DEV_ONLY_WATCH_EVENTS === 'true' || false,
})
return (
<div style={{ height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<div style={{ height: '100%', display: 'block', justifyContent: 'center', alignItems: 'center' }}>
<ProcaptchaPow config={config} />
</div>
)
Expand Down
6 changes: 6 additions & 0 deletions dev/config/src/vite/vite.backend.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export default async function (
...(process.env.PROSOPO_DEFAULT_NETWORK && {
'process.env.PROSOPO_DEFAULT_NETWORK': JSON.stringify(process.env.PROSOPO_DEFAULT_NETWORK),
}),
...(process.env.PROSOPO_SUBSTRATE_ENDPOINT && {
'process.env.PROSOPO_SUBSTRATE_ENDPOINT': JSON.stringify(process.env.PROSOPO_SUBSTRATE_ENDPOINT),
}),
...(process.env.PROSOPO_CONTRACT_ADDRESS && {
'process.env.PROSOPO_CONTRACT_ADDRESS': JSON.stringify(process.env.PROSOPO_CONTRACT_ADDRESS),
}),
}

logger.info(`Defined vars ${JSON.stringify(define, null, 2)}`)
Expand Down
5 changes: 2 additions & 3 deletions dev/scripts/src/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ function getDatasetFilePath() {
}

function getDefaultProvider(): IProviderAccount {
const host = process.env.PROSOPO_PROVIDER_HOST || 'localhost'
return {
url: process.env.PROSOPO_API_PORT
? `http://localhost:${process.env.PROSOPO_API_PORT}`
: 'http://localhost:9229',
url: process.env.PROSOPO_API_PORT ? `http://${host}:${process.env.PROSOPO_API_PORT}` : `http://${host}:9229`,
fee: 10,
payee: Payee.dapp,
stake: Math.pow(10, 13),
Expand Down
Loading
Loading