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

Munawarmojademo #230

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b745e95
Update issue templates
Munawarmoja Nov 8, 2024
dfcaa86
Update issue templates
Munawarmoja Nov 8, 2024
766f526
Create Munawarmoja
Munawarmoja Nov 8, 2024
9c19201
Create Munawarmoja
Munawarmoja Nov 8, 2024
b877131
Create generator-generic-ossf-slsa3-publish.yml
Munawarmoja Nov 9, 2024
45f1c10
Merge pull request #3 from Munawarmoja/Munawarmoja-patch-1
Munawarmoja Nov 9, 2024
c1c429a
Update .env.example
Munawarmoja Nov 12, 2024
87379c9
Rename deployment.md to deployment.md gibee
Munawarmoja Nov 12, 2024
b81babd
Update .env.example
Munawarmoja Nov 13, 2024
04b2969
Update README.md
Munawarmoja Nov 13, 2024
3072fbd
Update README.md
Munawarmoja Nov 13, 2024
af7a75e
Update README.md
Munawarmoja Nov 13, 2024
4321c33
Update README.md
Munawarmoja Nov 13, 2024
d9cec9e
Update docker-compose.yml
Munawarmoja Nov 13, 2024
51cd0e5
Update README.md
Munawarmoja Nov 13, 2024
4dfe7c9
demo ap
Munawarmoja Nov 13, 2024
6785c81
Update demo
Munawarmoja Nov 13, 2024
7ec4c89
Update README.md
Munawarmoja Nov 13, 2024
9acc7e2
Update README.md
Munawarmoja Nov 13, 2024
429b469
Update README.md
Munawarmoja Nov 13, 2024
c89cef7
Update README.md
Munawarmoja Nov 13, 2024
9f3cbc5
Update README.md
Munawarmoja Nov 13, 2024
76ec289
Update README.md
Munawarmoja Nov 13, 2024
e0cc852
Update README.md
Munawarmoja Nov 13, 2024
6f67c67
Update README.md
Munawarmoja Nov 13, 2024
4e6e3cd
Create Color
Munawarmoja Nov 13, 2024
33ca967
Update README.md
Munawarmoja Nov 13, 2024
7fb43d2
Update README.md
Munawarmoja Nov 13, 2024
6d19db3
Update .env.example
Munawarmoja Nov 13, 2024
b1ff050
Update .env.example
Munawarmoja Nov 13, 2024
ee6d982
Update README.md
Munawarmoja Nov 14, 2024
a88c7ca
Update README.md
Munawarmoja Nov 14, 2024
aaba545
Update README.md
Munawarmoja Nov 14, 2024
de04e73
Update README.md
Munawarmoja Nov 14, 2024
f6cbf5e
Update Munawarmoja
Munawarmoja Nov 14, 2024
d8fb038
Update README.md
Munawarmoja Nov 14, 2024
6dc2103
Update Munawarmoja
Munawarmoja Nov 14, 2024
ff28635
Update README.md
Munawarmoja Nov 15, 2024
6449539
Update README.md
Munawarmoja Nov 15, 2024
0f4f4ad
Update README.md.
Munawarmoja Nov 15, 2024
6206d0d
Update README.md
Munawarmoja Nov 15, 2024
de34565
Update .env.example
Munawarmoja Nov 15, 2024
9ecd567
Update README.md
Munawarmoja Nov 16, 2024
2f248e2
Update docker-compose.yml
Munawarmoja Nov 16, 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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# # this is a comment:
# FOO=value
# ```

#
#
#
Expand All @@ -23,6 +22,7 @@ BACKEND_DOMAIN_NAME=backend.example.com
# Obtain the following 2 values on the Pi Developer Portal (open develop.pi in the Pi Browser).

# Domain validation key:
https://github.com.munawarmojavalidation-key.txtb326b315d412570cbfa80e810e6f069e364b65eef8374a4c995264501110d518a8455d30c753c197f3aae087db225fe9f051b3080293ba45be3c0aa6b7b76435f6e156bb951c8883117f9b3a26e895fc82b6b264c9cf49f3922a3f2ab36282fcc460889388b307f90018d834b02b9c7582529014233b75a18806041b3cac821
DOMAIN_VALIDATION_KEY=todo_developer_portal
# Pi Platform API Key:
PI_API_KEY=todo_developer_portal
Expand Down
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/Color
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
<resources>
<color name="colorPrimary">#FFFFFF</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#FF4081</color>
</resources>
15 changes: 15 additions & 0 deletions .github/Munawarmoja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
66 changes: 66 additions & 0 deletions .github/workflows/generator-generic-ossf-slsa3-publish.yml
Munawarmoja marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow lets you generate SLSA provenance file for your project.
# The generation satisfies level 3 for the provenance requirements - see https://slsa.dev/spec/v0.1/requirements
# The project is an initiative of the OpenSSF (openssf.org) and is developed at
# https://github.com/slsa-framework/slsa-github-generator.
# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier.
# For more information about SLSA and how it improves the supply-chain, visit slsa.dev.

name: SLSA generic generator
on:
workflow_dispatch:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
outputs:
digests: ${{ steps.hash.outputs.digests }}

steps:
- uses: actions/checkout@v4

# ========================================================
#
# Step 1: Build your artifacts.
#
# ========================================================
- name: Build artifacts
run: |
# These are some amazing artifacts.
echo "artifact1" > artifact1
echo "artifact2" > artifact2

# ========================================================
#
# Step 2: Add a step to generate the provenance subjects
# as shown below. Update the sha256 sum arguments
# to include all binaries that you generate
# provenance for.
#
# ========================================================
- name: Generate subject for provenance
id: hash
run: |
set -euo pipefail

# List the artifacts the provenance will refer to.
files=$(ls artifact*)
# Generate the subjects (base64 encoded).
echo "hashes=$(sha256sum $files | base64 -w0)" >> "${GITHUB_OUTPUT}"

provenance:
needs: [build]
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: "${{ needs.build.outputs.digests }}"
upload-assets: true # Optional: Upload to a new release
141 changes: 141 additions & 0 deletions Munawarmoja
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

Pi Demo App Flows

- [Authentication](#authentication)
- [Pi.authenticate()](#1-obtain-user-data-with-piauthenticate-sdk-method)
- [GET /me Platform API endpoint](#2-verify-the-user-by-calling-pi-platform-api-get-me-endpoint)
- [Payments](#payments)
- [onReadyForServerApproval](#1-onreadyforserverapproval)
- [onReadyForServerCompletion](#2-onreadyforservercompletion)
- [onCancel](#3-oncancel)
- [onError](#4-onerror)
- [onIncompletePaymentFound](#onincompletepaymentfound)

## Authentication

User authentication consists of two steps:

1. obtaining user accessToken using Pi SDK
2. verifying accessToken using Pi Platform API

<br />

> Disclaimer:
>
> Pi SDK method Pi.authenticate() should only be used to retrieve user accessToken and MUST be verified on the backend side of your app.
>
> For a detailed guide on how to use Pi SDK, please refer to [SDK Docs](https://github.com/pi-apps/pi-platform-docs/blob/master/SDK_reference.md)
>
> Pi Platform API should remain the only source of truth about user data in your app (a malicious user could tamper with the requests and send you wrong data).
>
> For a detailed guide on how to use Pi Platform API, please refer to [Platform API Docs](https://github.com/pi-apps/pi-platform-docs/blob/master/platform_API.md)

<br />

### 1. Obtain user data with Pi.authenticate() SDK method

Pi.authenticate() method takes in two arguments: scopes and onIncompletePaymentFound and returns AuthResult object with different keys available.

scopes determine what keys are available on the AuthResult object. For full documentation on available scopes, please refer to [SDK Docs](https://github.com/pi-apps/pi-platform-docs/blob/master/SDK_reference.md#scopes).

onIncompletePaymentFound is a function that connects both Authorization and Payments flows. To preview example implementation, proceed to [onIncompletePaymentFound](#onincompletepaymentfound) section.

// frontend/src/shop/index.ts

const signIn = async () => {
const scopes = ["username", "payments"];
const authResponse = await window.Pi.authenticate(scopes, onIncompletePaymentFound);

/* pass obtained data to backend */
await signInUser(authResponse);

/* use the obtained data however you want */
setUser(authResponse.user);
};

const signInUser = (authResult: any) => {
axiosClient.post("/signin", { authResult }, config);

return setShowModal(false);
};
<br />

### 2. Verify the user by calling Pi Platform API GET /me endpoint

<br />



Pi Demo App

https://github.com/Munawarmoja/demo
Pi Demo App is an example of how you can implement the various required flows in your app's code.
It aims to show you how to use Pi Platform API on the backend side and Pi SDK on the frontend side of your app.


It is composed of two major parts:

* **backend**: a backend app (a very simple JSON API built using Node and ExpressJS)
* **frontend**: a single-page frontend app (built using React and create-react-app)


Read [`doc/development.md`](./doc/development.md) to get started and learn how to run this app in development.

> **WARNING**
>
> The demo app uses express session cookies which, in the Sandbox environment, are not correctly saved on the client on some browsers.
> To properly test all of the features of the Demo App, we recommend you to open the sandbox app using Mozilla Firefox.


## Deployment

Read [`doc/deployment.md`](./doc/deployment.md) to learn how to deploy this app on a server using Docker and docker-compose.


## Flows

To dive into the implementation of the flows that support the demo app features, please refer to
[Pi Demo App Flows](./FLOWS.md).




Frontend Javascript SDK

The JS SDK is the frontend SDK, designed to be used in your HTML pages or Single-Page Apps, served in the Pi Browser.

In order to enable the SDK to function correctly, you need to declare your apps on the Developer Portal (open
develop.pi in the Pi Browser to access the Developer Portal).

This SDK is not for a server-side NodeJS app.


In order to make sure that all involved parties (your app, your server, the Pi servers, and the Pi Blockchain) are in sync,
the payment needs to go through a Server-Side Approval flow (for User-to-App payment) and/or a Server-Side Completion
flow (for all types of payments).

Please refer to:
* [the full Payments documentation](./payments.md) to learn about the complete payment flow
* [the Advanced Payments documentation](./payments_advanced.md) to learn about App-to-User payment flow
* [the Platform API documentation](./platform_API.md) to learn how to confirm the payment and acknowledge it from your
server
* [the client SDK documentation](./SDK_reference.md) to learn about Pi Apps SDK and provided methods in detail
* [the Demo App](https://github.com/pi-apps/demo) to view an example of how you can implement the various required flows in your app's code



# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Pi Demo App
validation-key
https://github.com.munawarmoja/validation-key.txtb326b315d412570cbfa80e810e6f069e364b65eef8374a4c995264501110d518a8455d30c753c197f3aae087db225fe9f051b3080293ba45be3c0aa6b7b76439


Pi Demo App is an example of how you can implement the various required flows in your app's code.
It aims to show you how to use Pi Platform API on the backend side and Pi SDK on the frontend side of your app.
Expand All @@ -10,8 +12,6 @@ It is composed of two major parts:
* **frontend**: a single-page frontend app (built using React and create-react-app)


## Initial Development

Read [`doc/development.md`](./doc/development.md) to get started and learn how to run this app in development.

> **WARNING**
Expand All @@ -29,3 +29,29 @@ Read [`doc/deployment.md`](./doc/deployment.md) to learn how to deploy this app

To dive into the implementation of the flows that support the demo app features, please refer to
[Pi Demo App Flows](./FLOWS.md).




Frontend Javascript SDK

The JS SDK is the frontend SDK, designed to be used in your HTML pages or Single-Page Apps, served in the Pi Browser.

In order to enable the SDK to function correctly, you need to declare your apps on the Developer Portal (open
develop.pi in the Pi Browser to access the Developer Portal).

This SDK is not for a server-side NodeJS app.


In order to make sure that all involved parties (your app, your server, the Pi servers, and the Pi Blockchain) are in sync,
the payment needs to go through a Server-Side Approval flow (for User-to-App payment) and/or a Server-Side Completion
flow (for all types of payments).

Please refer to:
* [the full Payments documentation](./payments.md) to learn about the complete payment flow
* [the Advanced Payments documentation](./payments_advanced.md) to learn about App-to-User payment flow
* [the Platform API documentation](./platform_API.md) to learn how to confirm the payment and acknowledge it from your
server
* [the client SDK documentation](./SDK_reference.md) to learn about Pi Apps SDK and provided methods in detail
* [the Demo App](https://github.com/pi-apps/demo) to view an example of how you can implement the various required flows in your app's code

10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
version: "3.9"
services:

apt-get update && \
apt-get install -y zip apt-transport-https ca-certificates curl gnupg-agent software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
apt-get update && \
apt-get install -y docker-ce docker-ce-cli containerd.io && \
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose

reverse-proxy:
build: ./reverse-proxy
environment:
Expand Down