Skip to content

GraoMelo/login

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Available Scripts

Description

GetLogin implements an OpenID Connect authentication through OAuth 2 (implicit flow - client-side only).

Last project build hosted at getlogin.eth.

ETHCC2020 - Daniel Nagy: "Decentralized User Account Management"

Register your app in GetLogin smart contract

  1. Get last contract address from url: https://swarm-gateways.net/bzz:/getlogin.eth/xsettings

  2. Register as user with method createUser(usernameHash) where usernameHash is keccak256 hash of your username. Or pass if you already registered.

  3. Register application with method createApplication. Store application id which will return this method.

  4. Add allowed application urls (urls where your app is hosted) with addApplicationUrl

Inject GetLogin to your dApp

Add <script async src="https://swarm-gateways.net/bzz:/getlogin.eth/api/last.js"></script> to <head>

Init:

window.getLoginApi.init(appId, 'https://swarm-gateways.net/bzz:/getlogin.eth/', redirectUrl)
.then(data => {
    console.log(data);
});

where appId is your app id stored in step 3 of registration app instruction, redirectUrl is your app url.

Call methods: window.getLoginApi.getUserInfo().then(data => alert(JSON.stringify(data))).catch(e => alert(e));

Call dApp contract methods

Set contract ABI: window.getLoginApi.setClientAbi(abi);

Call getNotes method which defined in your dapp contract:

window.getLoginApi.callContractMethod(address, 'getNotes', usernameHash)
.then(data => {
    console.log(data);
})
.catch(e => {
    console.log(e);
});

address is your dapp address

Send transaction to your dapp contract:

window.getLoginApi.sendTransaction(address, 'createNote', noteText, {resolveMethod: 'mined'})
.then(data => {
    console.log(data);
})
.catch(e => {
    console.log(e);
});

address is your dapp address

createNote is your dapp method defined in contract

One important param is resolveMethod. Values of this param can be:

'mined' - fired when tx sent and mined (slow)

'transactionHash' - when tx sent (fast)

Building project

In the project directory, you can run:

yarn - install dependencies

yarn build - build project

yarn start - start project locally

About

Decentralized Single Sign-on for Web and Mobile apps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 90.7%
  • Solidity 8.1%
  • Other 1.2%