Core API

Auth Core API

Auth is responsible for all processes connected with user accounts, including creating and updating them, authentication, receiving tokens, logging in and out.

It has many methods that provides different types of access:

  1. Login with Username and Password

  2. Login with auth_key

  3. logout

  4. signup

  5. getUsersList

  6. updateUser

  7. updateToken

  8. updateAvatar

  9. getUserFromStorage

  10. saveUserToStorage

  11. getUserById

  12. getToken

  13. getVersion

Login with Username and Password

This method is called for getting access to the account with the help of username and password. Here we have an object credentials that contains user login and password.

import GudHub from '@gudhub/core';
const gudhub = new GudHub();

let credentials = {
    username : "login",
    password : "password"
}

await gudhub.login(credentials);
Argument Name Type Description
credentials object contains login and password

In response, we get an object with access information:

{
    "accesstoken": "juirlqoyndjcxkljgcadsldvag_hnvzieubb.eio",
    "app_init": 26749,
    "auth_key": "bMfVNw8yvJHGjJVHJghkgye3dkuy89dgZIzvXLn3KjqbMQ+B5wOA3gKssFzPPDMhhnVk",
    "expirydate": 1633974987485,
    "fullname": "John Dow",
    "user_id": 1354,
    "username": "john@dow.com",
}

Login with auth_key

This is the second way that allows to get access. It takes the authentication key as an argument. Due to this method you automatically use most of the other methods.

import {GudHub} from '@gudhub/gudhub';

let auth_key = "bMfVNw8yvJHGjJVHJghkgye3dkuy89dgZIzvXLn3KjqbMQ+B5wOA3gKssFzPPDMhhnVk";

const gudhub = new GudHub(auth_key);

In response it returns a JSON object:

{
    "accesstoken": "jikwkolpe_ba.fgergwed-n-_wjm.thstngje_-_v",
    "app_init": 26502,
    "auth_key": "NWfWIMAcjdskKJNKJB;,DLAKNkjhsiouoiiugtyRUTIU8967rgsja82jjKC+Ya/zNSGF4VKUq25\n1JqIf/mZXA==",
    "avatar_128": "https://gudhub.com/avatars/1627_8451_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/1627_8451_512.jpg",
    "expirydate": 1643872865040,
    "fullname": "John Dow",
    "user_id": 1000,
    "username": "john@dow.com"
}

Also, you can use additional parameters. Due to them you can send requests to another server. It is useful for development.

import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub(auth_key,{
    server_url : "https://gudhub.com/GudHub", 
    wss_url : "wss://gudhub.com/GudHub/ws/app/", 
    initWebsocket : false
});
Name Type Description
server_url string contains server url
wss_url string contains web socket url that is request endpoint
initWebsocket boolean shows whether a connection to the web socket is allowed

logout

This method is used when the user wants to log out. It takes token as an argument.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

gudhub.logout(token);
Argument Name Type Description
token string using for getting access

As a result, we get a success operation for this token:

Logout OK for token: bd.wqffmjipbbyuif-rhclprjrsbcqsndqxfcbeq_jd

signup

This method is called when a user register a new account. The data of the new user will be added to the data base and the unique authentication key will be given to the user. There is an user object as an argument.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);
let user = {
    "fullname":"Johana Dow",
    "password":"social6039",
    "username":"johana@dow.com"
}

gudhub.signup(user);
Argument Name Type Description
user object contains new user`s data

In response, we will get an object with user access data:

{
    "accesstoken": "eqe-ylcdcbjcvdddgahi_lba_hi.bdnsdadsaspxfvmt",
    "app_init": 26749,
    "auth_key": "bMfVNasjfgj36442ksq82aWs6gZIzvXLn3KjqbMQ+B5wOA3gKssFBKJGJgmnggkjFGG",
    "expirydate": 163843545366,
    "fullname": "John Dow",
    "user_id": 1578,
    "username": "john@dow.com",
}

getUsersList

This method is called during the search for users to share. Namely, when you enter a keyword into the search box, GudHub displays all users whose names match that word.

import GudHub from '@gudhub/core';
const authkey = 'KJKHCksdkjslkdlsklk/csoka';
const gudhub = new GudHub(authkey);

gudhub.getUsersList(keyword);
Argument Name Type Description
keyword string word entered as a search request

In response will be an array of matched users.

[{
    "expirydate": 0,
    "fullname": "Yen Mccullough",
    "user_id": 1577,
    "username": "qomevi@mailinator.com",
},
{
    "expirydate": 1,
    "fullname": "Yen Krickot",
    "user_id": 1571,
    "username": "krickot@nintin.com",
},...]

updateUser

This method is used for updating user data. It take an existing user data.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

let userData = {
    user: {...}
}

let updatedUser = await gudhub.updateUser(userData);
console.log(updatedUser)
Argument Name Type Description
userData object contains user object with user`s overview

In response, it returns updating user data.

{
    "avatar_128": "https://gudhub.com/avatars/1578_925_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/1578_925_512.jpg",
    "expirydate": 0,
    "fullname": "Johna Dow",
    "user_id": 1578,
    "username": "john@dow.com",
}

updateToken

This method updates current token. As an argument, it takes user`s authentication key.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

gudhub.updateToken(auth_key)
Argument Name Type Description
auth_key string personal authentication key

Token automatically updates every 9 hours.

token: wqkuzkiswsvitfqjl-onbbbnbbjhhaetwbpsbenmmv

updateAvatar

This method is used when user changes his photo in account. It takes data of the image as an argument.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

let updatedAvatar = await gudhub.updateAvatar(imageData);
console.log(updatedAvatar)
Argument Name Type Description
imageData base64 encrypted image; accepts .jpg, .png, .gif

In response will be an updated user data:

{
    "avatar_128": "https://gudhub.com/avatars/1578_6824_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/1578_6824_512.jpg",
    "expirydate": 0,
    "fullname": "John Dow",
    "user_id": 1578,
    "username": "john@dow.com",
}

getUserFromStorage

This method is used for getting needed user during sharing. It takes user ID.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

let userFromStorage = gudhub.getUserFromStorage(id);
console.log(userFromStorage)
Argument Name Type Description
id number unique user ID

And returns object of needed user data:

{
    "avatar_128": "https://gudhub.com/avatars/1176_4665_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/1176_4665_512.jpg",
    "expirydate": 0,
    "fullname": "John Dow",
    "user_id": 1145,
    "username": "john@dow.com",
}

saveUserToStorage

Due to this method all users searched for will be added to the storage.

Storage is a list of users that allows to do not upload user`s data from server for the second time. This process optimize a work of the server. Users in sharing are taken from this list.

saveUserToStorage takes an user object as an argument.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

let saveUser = {
    avatar_128: "https://gudhub.com/avatars/1176_4665_128.jpg",
    avatar_512: "https://gudhub.com/avatars/1176_4665_512.jpg",
    expirydate: 0,
    fullname: "John Dow",
    user_id: 1145,
    username: "john@dow.com",
}

let saveUserToStorage = gudhub.saveUserToStorage(saveUser);
console.log(saveUserToStorage)
Argument Name Type Description
saveUser object contains user`s object

Returns the object of user overview:

{
    "avatar_128": "https://gudhub.com/avatars/1176_4665_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/1176_4665_512.jpg",
    "expirydate": 0,
    "fullname": "John Dow",
    "user_id": 1145,
    "username": "john@dow.com",
}

getUserById

This method gets user from list of user that have access to the application. As an argument, it takes user`s ID.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

let gottenUserById = await gudhub.getUserById(userId);
console.log(gottenUserById)
Argument Name Type Description
userId number unique user ID

It returns object with user`s data:

{
    "expirydate": 0,
    "fullname": "John Dow",
    "user_id": 1571,
    "username": "john@dow.com",
}

getToken

This method is called for getting current token. It has no arguments.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

await gudhub.getToken();

getToken() returns current token:

token: wqkuzkiswsvitfqjl-onbbbnbbjhhaetwbpsbenmmv

getVersion

As well as getToken, getVersion has no argument. It is called to get version of JS.

import GudHub from '@gudhub/core';
const authkey = 'kjzkjdkdjsklsljdlskv';
const gudhub = new GudHub(authkey);

gudhub.getVersion();

In response we will get a new HTML page with a number of JS version.

2.7.8.7