@wral/studio.mods.auth

0.3.7 • Public • Published

Authentication Mod for Studio App

This is a mod for Studio App.

Installation

Include in your Studio App HTML implementation:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Your Studio App</title>
    <script type="module" src="https://cdn.wral.studio/studio-app.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <studio-app>

        <!-- Hello, World! Studio Mod -->
        <studio-mod src="https://cdn.wral.studio/mods/auth/release/latest/auth.es.js"></studio-mod>
    
    </studio-app>
</body>
</html>

Usage

The auth mod subscribes to the following:

  • studio.wral::mod-auth::token-request, payload: { callback: (token, error) => {} }

The auth mod provides bearer tokens to other mods by request. Other mods can request a token by publishing a token-request event and providing a callback.

/**
 * @param {Studio} studio
 * @return {Promise<string>} bearer token
 */
async function getToken(studio) {
    return new Promise((resolve, reject) => {
        studio.pub('studio.wral::mod-auth', 'token-request', {
            callback: (token, error) => {
                if (error) {
                    reject(error);
                } else {
                    resolve(token);
                }
            },
        });
    });
}

Readme

Keywords

none

Package Sidebar

Install

npm i @wral/studio.mods.auth

Weekly Downloads

10

Version

0.3.7

License

UNLICENSED

Unpacked Size

249 kB

Total Files

25

Last publish

Collaborators

  • jforbes
  • kbarbour
  • sburbridge
  • cbcnewmedia