---
url: https://gudhub.com/docs/core-api/auth-core-api/
title: "Auth Core API\n                #"
description: "Auth is responsible for all processes connected with user accounts, including creating and updating them, authentication, receiving tokens, logging in and out."
lang: uk
updated: 2026-09-08T15:38:29.047Z
---

# Auth Core API [#](https://gudhub.com/docs/core-api/auth-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](#login-with-username-and-password)
    
2.  [Login with auth\_key](#login-with-auth-key)
    
3.  [Login with access token](#login-with-access-token)
    
4.  [logout](#logout)
    
5.  [signup](#signup)
    
6.  [getUsersList](#getuserslist)
    
7.  [updateUser](#updateuser)
    
8.  [updateToken](#updatetoken)
    
9.  [updateAvatar](#updateavatar)
    
10.  [getUserFromStorage](#getuserfromstorage)
     
11.  [saveUserToStorage](#saveusertostorage)
     
12.  [getUserById](#getuserbyid)
     
13.  [getToken](#gettoken)
     
14.  [getVersion](#getversion)
     
15.  [getUserWorkspace](#getuserworkspace)
     

## Login with Username and Password [#](https://gudhub.com/docs/core-api/auth-core-api/#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.

Copy

```js
async gudhub.login(credentials)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| credentials | `object` | _contains login and password_ |

Copy

```js
import GudHub from '@gudhub/core';

let credentials = {
    username : "john@dow.com",
    password : "hdsJJ493"
}

const gudhub = new GudHub();
let login = await gudhub.login(credentials);
console.log(login)
```

In response, we get an object with access information:

Copy

```json
{
    "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 [#](https://gudhub.com/docs/core-api/auth-core-api/#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.

Copy

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

let auth_key = "bMfVNw8yvJHGjJVHJghkgye3dkuy89dgZIzvXLn3KjqbMQ+B5wOA3gKssFzPPDMhhnVk";

const gudhub = new GudHub(auth_key);
```

In response it returns a JSON object:

Copy

```json
{
    "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.

Copy

```js
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_ |

## Login with access token [#](https://gudhub.com/docs/core-api/auth-core-api/#login-with-access-token)

This is the third way that allows to get access. It takes object as a second parameter. Due to this method you automatically use most of the other methods.

Copy

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

const accesstoken = "accesstoken";

const gudhub = new GudHub(null, {
    accesstoken: accesstoken,
    expirydate: new Date().getTime() + 300000 // 300000ms is a 5 min
});
```

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

Copy

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


const gudhub = new GudHub(null, {
    accesstoken: accesstoken,
    expirydate: new Date().getTime() + 300000 // 300000ms is a 5 min
    server_url : "https://gudhub.com/GudHub", 
    wss_url : "wss://gudhub.com/GudHub/ws/app/", 
    initWebsocket : false
});
```

| Name | Type | Description |
| :-- | :-- | :-- |
| accesstoken | `string` | _access token_ |
| expirydate | `number` | _Date in milliseconds when token will be outdated_ |
| 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() [#](https://gudhub.com/docs/core-api/auth-core-api/#logout)

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

Copy

```js
await gudhub.logout(token)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| token | `string` | _using for getting access_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';

(async ()=>{
    const gudhub = new GudHub(authkey);
    await gudhub.logout(token);
})();
```

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

Copy

```json
Logout OK for token: bd.wqffmjipbbyuif-rhclprjrsbcqsndqxfcbeq_jd
```

## signup() [#](https://gudhub.com/docs/core-api/auth-core-api/#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.

Copy

```js
await gudhub.signup(user)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| user | `object` | _contains new user\`s data_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
let user = {
    "fullname":"Johana Dow",
    "password":"sjdjj6544",
    "username":"johana@dow.com"
}

(async ()=>{
    const gudhub = new GudHub(authkey);
    await gudhub.signup(user);
})();
```

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

Copy

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

## getUsersList() [#](https://gudhub.com/docs/core-api/auth-core-api/#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.

Copy

```js
await gudhub.getUsersList(keyword)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| keyword | `string` | _word entered as a search request_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'KJKHCksdkjslkdlsklk/csoka';
let keyword= "Dow";

(async ()=>{
    const gudhub = new GudHub(authkey);
    await gudhub.getUsersList(keyword);
})();
```

In response will be an array of matched users.

Copy

```json
[{
    "expirydate": 0,
    "fullname": "John Dow",
    "user_id": 1577,
    "username": "john@dow.com",
},
{
    "expirydate": 1,
    "fullname": "Johana Dow",
    "user_id": 1571,
    "username": "johana@dow.com",
},...]
```

## updateUser() [#](https://gudhub.com/docs/core-api/auth-core-api/#updateuser)

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

Copy

```js
await gudhub.updateUser(userData)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| userData | `object` | _contains user object with user\`s overview_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
let userData = {
    user: {...}
}

(async ()=>{
    const gudhub = new GudHub(authkey);
    let updatedUser = await gudhub.updateUser(userData);
    console.log(updatedUser)
})();
```

In response, it returns updating user data.

Copy

```json
{
    "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() [#](https://gudhub.com/docs/core-api/auth-core-api/#updatetoken)

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

Copy

```js
await gudhub.updateToken(auth_key)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| auth\_key | `string` | _personal authentication key_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';

(async ()=>{
    const gudhub = new GudHub(authkey);
    await gudhub.updateToken(authkey);
})();
```

Token automatically updates every 9 hours.

Copy

```json
token: wqkuzkiswsvitfqjl-onbbbnbbjhhaetwbpsbenmmv
```

## updateAvatar() [#](https://gudhub.com/docs/core-api/auth-core-api/#updateavatar)

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

Copy

```js
await gudhub.updateAvatar(imageData)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| imageData | `base64` | _encrypted image; accepts .jpg, .png, .gif_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
let imageData = 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=...';

(async ()=>{
    const gudhub =  new GudHub(authkey);
    let updatedAvatar = await gudhub.updateAvatar(imageData);
    console.log(updatedAvatar)
})();
```

In response will be an updated user data:

Copy

```json
{
    "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() [#](https://gudhub.com/docs/core-api/auth-core-api/#getuserfromstorage)

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

Copy

```js
await gudhub.getUserFromStorage(id)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| id | `number` | _unique user ID_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
let id = 97765;

(async ()=>{
    const gudhub = new GudHub(authkey);
    let userFromStorage = await gudhub.getUserFromStorage(id);
    console.log(userFromStorage)
})();
```

And returns object of needed user data:

Copy

```json
{
    "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": 97765,
    "username": "john@dow.com",
}
```

## saveUserToStorage() [#](https://gudhub.com/docs/core-api/auth-core-api/#saveusertostorage)

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

Copy

```js
await gudhub.saveUserToStorage(saveUser)
```

> 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.

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| saveUser | `object` | _contains user\`s object_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
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",
}

(async ()=>{
    const gudhub = new GudHub(authkey);
    let saveUserToStorage = await gudhub.saveUserToStorage(saveUser);
    console.log(saveUserToStorage)
})();
```

Returns the object of user overview:

Copy

```json
{
    "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() [#](https://gudhub.com/docs/core-api/auth-core-api/#getuserbyid)

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

Copy

```js
await gudhub.getUserById(userId)
```

| Argument Name | Type | Description |
| :-- | :-- | :-- |
| userId | `number` | _unique user ID_ |

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';
let userId = 64774;

(async ()=>{
    const gudhub = new GudHub(authkey);
    let gottenUserById = await gudhub.getUserById(userId);
    console.log(gottenUserById)
})();
```

It returns object with user\`s data:

Copy

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

## getToken() [#](https://gudhub.com/docs/core-api/auth-core-api/#gettoken)

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

Copy

```js
await gudhub.getToken()
```

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';

(async ()=>{
    const gudhub = new GudHub(authkey);
    await gudhub.getToken();
})();
```

_getToken()_ returns current token:

Copy

```json
token: wqkuzkiswsvitfqjl-onbbbnbbjhhaetwbpsbenmmv
```

## getVersion() [#](https://gudhub.com/docs/core-api/auth-core-api/#getversion)

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

Copy

```js
await gudhub.getVersion()
```

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';

(async ()=>{
    const gudhub = new GudHub(authkey);
    gudhub.getVersion();
})();
```

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

Copy

```json
2.7.8.7
```

## getUserWorkspace() [#](https://gudhub.com/docs/core-api/auth-core-api/#getuserworkspace)

This method gets the list of users belonging to the current user's workspace. It has no arguments and always requests fresh data from the server. Every user in the response is cached to _storage_ via [saveUserToStorage](#saveusertostorage), the same way `getUserById` caches users it fetches.

Each user in the response now also includes a `groups` array listing the IDs of the groups that user belongs to. The `avatar_128`/`avatar_512` fields are only present for users who have an avatar set.

Copy

```js
await gudhub.getUserWorkspace()
```

Copy

```js
import GudHub from '@gudhub/core';

const authkey = 'kjzkjdkdjsklsljdlskv';

(async ()=>{
    const gudhub = new GudHub(authkey);
    let workspaceUsers = await gudhub.getUserWorkspace();
    console.log(workspaceUsers)
})();
```

It returns an array of the workspace's users:

Copy

```json
[{
    "groups": [18, 19],
    "user_id": 1010,
    "username": "ivan.petrenko@gmail.com",
    "fullname": "Ivan Petrenko",
    "expirydate": 0
},
{
    "groups": [226, 940],
    "user_id": 22,
    "username": "vasyl.pupkin@gudhub.com",
    "fullname": "Vasyl Pupkin",
    "avatar_128": "https://gudhub.com/avatars/22_6152_128.jpg",
    "avatar_512": "https://gudhub.com/avatars/22_6152_512.jpg",
    "expirydate": 0
},
{
    "groups": [226],
    "user_id": 2181,
    "username": "olena.kovalenko@gmail.com",
    "fullname": "Olena Kovalenko",
    "expirydate": 0
},...]
```
