How to use the netlify-cms-lib-auth.NetlifyAuthenticator function in netlify-cms-lib-auth

To help you get started, we’ve selected a few netlify-cms-lib-auth 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 netlify / netlify-cms / packages / netlify-cms-backend-bitbucket / src / AuthenticationPage.js View on Github external
'site/oauth2/authorize',
        ),
        app_id: this.props.config.getIn(['backend', 'app_id']),
        clearHash: this.props.clearHash,
      });
      // Complete implicit authentication if we were redirected back to from the provider.
      this.auth.completeAuth((err, data) => {
        if (err) {
          this.setState({ loginError: err.toString() });
          return;
        }
        this.props.onLogin(data);
      });
      this.authSettings = { scope: 'repository:write' };
    } else {
      this.auth = new NetlifyAuthenticator({
        base_url: this.props.base_url,
        site_id:
          document.location.host.split(':')[0] === 'localhost'
            ? 'cms.netlify.com'
            : this.props.siteId,
        auth_endpoint: this.props.authEndpoint,
      });
      this.authSettings = { provider: 'bitbucket', scope: 'repo' };
    }
  }
github netlify / netlify-cms / packages / netlify-cms-backend-gitlab / src / AuthenticationPage.js View on Github external
this.auth = new ImplicitAuthenticator({
        base_url: this.props.config.getIn(['backend', 'base_url'], 'https://gitlab.com'),
        auth_endpoint: this.props.config.getIn(['backend', 'auth_endpoint'], 'oauth/authorize'),
        app_id: this.props.config.getIn(['backend', 'app_id']),
        clearHash: this.props.clearHash,
      });
      // Complete implicit authentication if we were redirected back to from the provider.
      this.auth.completeAuth((err, data) => {
        if (err) {
          this.setState({ loginError: err.toString() });
          return;
        }
        this.props.onLogin(data);
      });
    } else {
      this.auth = new NetlifyAuthenticator({
        base_url: this.props.base_url,
        site_id:
          document.location.host.split(':')[0] === 'localhost'
            ? 'cms.netlify.com'
            : this.props.siteId,
        auth_endpoint: this.props.authEndpoint,
      });
    }
  }
github netlify / netlify-cms / packages / netlify-cms-backend-bitbucket / src / implementation.js View on Github external
getRefreshedAccessToken() {
    if (this.refreshedTokenPromise) {
      return this.refreshedTokenPromise;
    }

    // instantiating a new Authenticator on each refresh isn't ideal,
    if (!this.auth) {
      const cfg = {
        base_url: this.base_url,
        site_id: this.site_id,
      };
      this.authenticator = new NetlifyAuthenticator(cfg);
    }

    this.refreshedTokenPromise = this.authenticator
      .refresh({ provider: 'bitbucket', refresh_token: this.refreshToken })
      .then(({ token, refresh_token }) => {
        this.token = token;
        this.refreshToken = refresh_token;
        this.refreshedTokenPromise = undefined;
        this.updateUserCredentials({ token, refresh_token });
        return token;
      });

    return this.refreshedTokenPromise;
  }
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / AuthenticationPage.js View on Github external
handleLogin = e => {
    e.preventDefault();
    const cfg = {
      base_url: this.props.base_url,
      site_id:
        document.location.host.split(':')[0] === 'localhost'
          ? 'cms.netlify.com'
          : this.props.siteId,
      auth_endpoint: this.props.authEndpoint,
    };
    const auth = new NetlifyAuthenticator(cfg);

    const openAuthoring = this.props.config.getIn(['backend', 'open_authoring'], false);
    const scope = this.props.config.getIn(
      ['backend', 'auth_scope'],
      openAuthoring ? 'public_repo' : 'repo',
    );
    auth.authenticate({ provider: 'github', scope }, (err, data) => {
      if (err) {
        this.setState({ loginError: err.toString() });
        return;
      }
      if (openAuthoring) {
        return this.loginWithOpenAuthoring(data).then(() => this.props.onLogin(data));
      }
      this.props.onLogin(data);
    });

netlify-cms-lib-auth

Shared authentication functionality for Netlify CMS.

MIT
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis