GetLogin implements an OpenID Connect authentication through OAuth 2 (implicit flow - client-side only).
Last project build hosted at getlogin.eth.
-
Get last contract address from url:
https://swarm-gateways.net/bzz:/getlogin.eth/xsettings
-
Register as user with method
createUser(usernameHash)
whereusernameHash
is keccak256 hash of your username. Or pass if you already registered. -
Register application with method
createApplication
. Store application id which will return this method. -
Add allowed application urls (urls where your app is hosted) with
addApplicationUrl
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));
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)
In the project directory, you can run:
yarn
- install dependencies
yarn build
- build project
yarn start
- start project locally