npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

@wehmoen/ec-sdk

0.0.2 • Public • Published

SDK Methods

Init SDK

Call the Initialize() method when your app first loads to initialize the SDK:

var ec = require('@wehmoen/ec-sdk');

var api = ec.Initialize({
  app: 'eosconnect',
  callbackURL: 'https://localhost:3000/int/login',
  scope: ['login']
});

Parameters:

  • app: This is the name of the app that was registered in the EOSconnect dashboard
  • callbackURL: This is the URL that users will be redirected to after interacting with EOSconnect. It must be listed in the "Redirect URI(s)" list in the app settings EXACTLY the same as it is specified here
  • accessToken: If you have an oauth2 access token for this user already you can specify it here, otherwise you can leave it and set it later using api.setAccessToken(accessToken).
  • scope: This is a list of operations the app will be able to access on the user's account. At the moment EOSconnect only supports the login scope.

Get Login URL

The following method returns a URL that you can redirect the user to so that they may log in to your app through EOSconnect:

var link = api.getLoginURL(state);
console.log(link)
// => https://eosconnect.app/auth?client_id=[app]&redirect_uri=[callbackURL]&scopes=login

After logging in, EOSconnect will redirect the user to the "redirect_uri" specified in the login url above and add the following query string parameters for your app to use:

  • access_token: This is the oauth2 access token that is required to make any Steem API calls on behalf of the current user. Once you have this you need to tell the EOSconnect SDK to use it by either specifying it as a parameter to the init() method call or by calling api.setAccessToken([accessToken]).
  • expires_in: The number of seconds until the access token expires.
  • username: The username of the current user.

Get user profile

Once a user is logged in to your app you can call the following method to get the details of their account:

api.me().then(profile => { console.log(profile); }).catch(error => { console.log(error); });

If it is successful, the result will be a JSON object with the following properties:

"account_name": "steemthebest"
"head_block_num": 2496363
"head_block_time": "2018-06-25T02:57:16.000"
"privileged": false
"last_code_update": "1970-01-01T00:00:00.000"
"created": "2018-06-22T20:46:05.000"

Keywords

none

install

npm i @wehmoen/ec-sdk

Downloadsweekly downloads

0

version

0.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability