Coder Social home page Coder Social logo

josephgranata / access-control-tutorial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krpeacock/access-control-tutorial

0.0 0.0 0.0 144 KB

Motoko Bootcamp presentation on Motoko + Authentication

Home Page: https://qizwk-hqaaa-aaaab-qaida-cai.icp0.io/

JavaScript 89.39% CSS 3.01% HTML 4.20% Motoko 3.40%

access-control-tutorial's Introduction

Access Control

This project demonstrates a simple example of how to implement access control in a web application using Motoko and JS. The application tracks the number of times different users have clicked a button. We demonstrate two different strategies for authentication: using a secret key and authenticating with Internet Identity using the @dfinity/ii-login-button web component.

Demo

You can try out the demo here.

How to run locally

Prerequisites

Steps

  1. Clone this repo and install dependencies:
git clone [email protected]:krpeacock/access-control-tutorial.git
cd access-control-tutorial
npm install
  1. Start the local internet computer emulator:
dfx start --background --clean --host "127.0.0.1:4943"
  1. Deploy the canisters:
dfx deploy

You can open the app there in your browser, or you can run the vite dev server:

npm run dev

How it works

In the backend, the canister stores a map of counts with the principal as the key. The canister has three methods:

  • increment
  • getCount
  • getCounts

The increment method increments the count for the principal that calls it. The getCount method returns the count for the principal that calls it. The getCounts method returns the counts for all principals.

The frontend has a single page. It includes an input that converts the string into an Ed25519KeyIdentity. It displays the principal that you will be calling with, and then anytime you click the button, it will update the count for that principal and display the new count.

There is also a button to log in with Internet Identity. This will open a popup that will prompt you to log in with Internet Identity. Once you log in, it will display your principal and you can click the button to increment your count.

Finally, there is a table of all the identities that have been used with the site.

access-control-tutorial's People

Contributors

krpeacock avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.