How to use auth0-lock - 10 common examples

To help you get started, we’ve selected a few auth0-lock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github auth0-samples / auth0-vue-samples / 05-Authorization / src / auth / AuthService.js View on Github external
accessToken;
  expiresAt;

  authenticated = this.isAuthenticated()
  admin = this.isAdmin()
  authNotifier = new EventEmitter()
  userProfile;

  constructor () {
    // Add callback Lock's `authenticated` event
    this.lock.on('authenticated', this.setSession.bind(this))
    // Add callback for Lock's `authorization_error` event
    this.lock.on('authorization_error', error => console.log(error))
  }

  lock = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, {
    autoclose: true,
    auth: {
      audience: AUTH_CONFIG.apiUrl,
      responseType: 'token id_token',
      params: {
        scope: 'openid profile read:messages'
      }
    }
  })

  login () {
    // Call the show method to display the widget.
    this.lock.show()
  }

  setSession (authResult) {
github BadrIT / bractal / src / modules / todos / Auth.js View on Github external
languageDictionary: {
    title: 'Bractal Auth0 Tutorial',
    signUpTitle: 'Bractal Auth0 Tutorial',
  },
  auth: {
    redirectUrl: 'http://localhost:3000/todos/list',
    responseType: 'token',
    scope: 'openid',
    audience: 'https://bractal.auth0.com/api/v2/',
    issuer: 'https://bractal.auth0.com',
  },
  allowShowPassword: true,
  autoclose: true,
};

const lock = new Auth0Lock(clientId, domain, options);

// Listen for the authenticated event and get profile
lock.on('authenticated', (authResult) => {
  lock.getUserInfo(authResult.accessToken, (error) => {
    if (error) {
      // Handle error
      return;
    }
    console.log(authResult);
    localStorage.setItem('accessToken', authResult.accessToken);
  });
});

export const logout = () => lock.logout({
  returnTo: 'http://localhost:3000/todos/',
});
github TailorDev / crick / web / src / Auth / reducer.js View on Github external
import { CALL_API } from 'redux-api-middleware';
import { push } from 'react-router-redux';
import { API_ERROR } from '../Errors/reducer';
import type { State, Dispatch, GetState, ThunkAction, Action } from '../types';

// State
export type AuthState = {
  id: ?string,
  token: ?string,
  login: ?string,
  avatar_url: ?string,
  api_token: ?string,
  isAuthenticated: boolean,
};

const lock = new Auth0Lock(
  process.env.REACT_APP_AUTH0_CLIENT_ID,
  process.env.REACT_APP_AUTH0_DOMAIN,
  {
    auth: {
      params: {
        scope: 'openid profile',
        audience: process.env.REACT_APP_AUTH0_AUDIENCE,
        // It looks like this one is actually used so let's configure it too.
        redirectUri: process.env.REACT_APP_AUTH0_REDIRECT_URL || '',
        responseType: 'token',
      },
    },
    theme: {
      logo: 'https://crick.io/img/logo-crick-square-150px.png',
    },
  }
github sedubois / relate / components / Lock.js View on Github external
function showLock(nextPathname) {
  const secret = uuid.v4();
  storeSecret(secret);
  lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN, {
    auth: {
      redirectUrl: `${BASE_URL}/auth/callback`,
      responseType: 'token',
      params: {
        state: JSON.stringify({
          secret,
          nextPathname,
        }),
      },
    },
    container: LOCK_CONTAINER_ID,
    // other options see https://auth0.com/docs/libraries/lock/v10/customization
  });
  lock.show();
}
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / lib / auth0.ts View on Github external
export function getAuth0LockInstance(options = {}): Auth0LockStatic {
  if (lockInstance === undefined) {
    lockInstance = new Auth0Lock(auth0Env.clientId, auth0Env.domain, {
      // TODO: pull language form i18next
      language: 'en',
      configurationBaseUrl: auth0Env.baseUrl,
      additionalSignUpFields: [
        {
          name: 'given_name',
          placeholder: 'Given Name',
        },
        {
          name: 'family_name',
          placeholder: 'Family Name',
        },
      ],
      auth: {
        responseType: 'token id_token',
        sso: false,
github auth0-samples / auth0-react-samples / 01-Embedded-Login / src / Auth / Auth.js View on Github external
import { EventEmitter } from 'events'
import Auth0Lock from 'auth0-lock';
import { AUTH_CONFIG } from './auth0-variables';
import history from '../history';

export default class Auth extends EventEmitter {

  lock = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, {
    oidcConformant: true,
    autoclose: true,
    auth: {
      redirectUrl: AUTH_CONFIG.callbackUrl,
      responseType: 'token id_token',
      audience: `https://${AUTH_CONFIG.domain}/userinfo`
    }
  });

  constructor() {
    super();
    this.handleAuthentication();
    // binds functions to keep this context
    this.login = this.login.bind(this);
    this.logout = this.logout.bind(this);
    this.isAuthenticated = this.isAuthenticated.bind(this);
github ReactNativeGallery / reactnative-gallery-web / utils / auth.js View on Github external
const getLock = (options) => {
  // eslint-disable-next-line
  const Auth0Lock = require('auth0-lock').default
  return new Auth0Lock(process.env.AUTH_ID, process.env.AUTH_DOMAIN, options)
}
github ACloudGuru-Resources / Course-The_Complete_Serverless_Course / projects / 1 - Authentication with Auth0 / solution / part-2 / auth0-app-frontend / src / App.js View on Github external
super();

    const params = {
      autoclose: true,
      oidcConformant: true,
      auth: {
        audience: `${Config.API_BASE_URL}`,
        params: {
          scope: 'openid profile email'
        },
        responseType: 'token'
      }
    };

    // Instantiate the Auth0Lock library
    const lock = new Auth0Lock(
      Config.AUTH0_CLIENT_ID,
      Config.AUTH0_DOMAIN,
      params
    );
    this.lock = lock;

    // Listen for the authenticated event on the Auth0 lock library and call the 
    // onAuthenticated method
    this.lock.on('authenticated', this.onAuthentication)
  }
github KATT / next-with-apollo-airbnb-auth0-graphcool / components / Header.js View on Github external
componentDidMount() {
    const lock = new Auth0Lock(process.env.AUTH0_CLIENT_ID, process.env.AUTH0_DOMAIN, {
      auth: {
        redirectUrl: `${location.origin}/login?r=${this.props.pathname}`,
        responseType: 'token',
      },
    });
    this.lock = lock;

    lock.on('authenticated', (result) => {
      console.log('authenticated', result);
      lock.getUserInfo(result.accessToken, (error, profile) => {
        if (error) {
          console.error('getUserInfo error', error);
          return;
        }

        this.signinOrCreateUser(result.idToken, profile);

auth0-lock

Auth0 Lock

MIT
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis