Announcement

Collapse
No announcement yet.

Request for Authentication Documentation for External Application

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request for Authentication Documentation for External Application


    Hello friends,

    I need to authenticate a portal user with their login and password via an external application. Is there any documentation for this?

    For example, in my instance, I have a portal user with the following credentials:

    - Username: test
    - Password: test

    I want to use these credentials in an internally developed interface to allow the user to access these informations and data through this interface.

    Thank you.

    ---​

  • #2
    up plz

    Comment


    • #3
      https://docs.espocrm.com/development/api-client-php/ It is all in documentation. Use an api to get data for the given portal user.
      Rabii
      Web Dev | Freelancer

      Comment


      • #4
        Hello rabii

        Int to use my login and password, for example, in another interface. After entering these details, it should connect as it does on my EspoCRM instance. I know how to do this because this document doesn't address what I'm looking for. I've already configured token retrieval information in the backend, but it's not working."




        import React, { useState } from 'react';
        import axios from 'axios';
        import './Login.css';

        const Login = () => {
        const [formData, setFormData] = useState({
        username: '',
        password: ''
        });
        const [error, setError] = useState('');
        const [success, setSuccess] = useState('');

        const handleChange = (e) => {
        const { name, value } = e.target;
        setFormData({
        ...formData,
        [name]: value
        });
        };

        const handleSubmit = async (e) => {
        e.preventDefault();
        const { username, password } = formData;
        const encodedCredentials = btoa(`${username}:${password}`);
        try {
        const response = await axios.get('https://xxxxxxxxxx.com/api/v1/App/user', {
        headers: {
        'Authorization': `Basic ${encodedCredentials}`,
        'Content-Type': 'application/json'
        },
        withCredentials: true
        });
        setSuccess('Connexion réussie');
        setError('');
        // Rediriger l'utilisateur ou effectuer une autre action
        } catch (error) {
        setError('Erreur de connexion');
        setSuccess('');
        }
        };

        return (
        <div className="login-container">
        <div className="login-header">
        </div>

        <div className="login-form-container">
        <h2>Connexion</h2>
        <form onSubmit={handleSubmit}>
        <input
        type="email"
        name="username"
        placeholder="Email"
        value={formData.username}
        onChange={handleChange}
        required
        />
        <input
        type="password"
        name="password"
        placeholder="Mot de passe"
        value={formData.password}
        onChange={handleChange}
        required
        />
        {error && <div className="alert alert-danger mt-3">{error}</div>}
        {success && <div className="alert alert-success mt-3">{success}</div>}
        <input type="submit" value="SE CONNECTER" />
        </form>
        <p>Vous n'avez pas de compte ? <a href="/register">Inscrivez-vous maintenant!</a></p>
        </div>
        </div>
        );
        };

        export default Login;​


        Comment


        • #5
          This is a front end, what is the code you are using in backend ? also if possible consider using https://docs.espocrm.com/development/api-client-js/ it would be much easier to use
          Rabii
          Web Dev | Freelancer

          Comment


          • #6
            Hello rabii

            Thanks for your help, I managed to authenticate but I receive a token: null.
            Click image for larger version

Name:	image.png
Views:	71
Size:	8.1 KB
ID:	108379

            Comment


            • #7
              Yeah because that user is not an ApiUser so it is normal that the token is empty.
              Rabii
              Web Dev | Freelancer

              Comment


              • #8


                Thanks
                Last edited by abidoss; 07-12-2024, 01:27 PM.

                Comment


                • #9
                  tbh i am not even sure what you want to achieve. Using api you can connect to the crm using any user's basic athentication credentials. Once you access the crm through api for the given user, the role and permissions are applied so the request will access only data for the given user.
                  Last edited by rabii; 07-12-2024, 01:32 PM.
                  Rabii
                  Web Dev | Freelancer

                  Comment


                  • rabii
                    rabii commented
                    Editing a comment
                    It is the same endpoint, the portal user is a user with type portal so you should be able to authenticate even portal user using the same endpoint.

                  • abidoss
                    abidoss commented
                    Editing a comment
                    [2024-07-17 07:40:17] ERROR: 405 Method Not Allowed Type: Slim\Exception\HttpMethodNotAllowedException Code: 405 Message: Method not allowed. Must be one of: GET, PUT, PATCH, DELETE File: C:\instance\vendor\slim\slim\Slim\Middleware\Routi ngMiddleware.php Line: 79 Trace: #0 C:\instance\vendor\slim\slim\Slim\Middleware\Routi ngMiddleware.php(44): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request)) #1 C:\instance\vendor\slim\slim\Slim\MiddlewareDispat cher.php(121): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner)) #2 C:\instance\vendor\slim\slim\Slim\Middleware\Error Middleware.php(76): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Slim\Psr7\Request)) #3 C:\instance\vendor\slim\slim\Slim\MiddlewareDispat cher.php(121): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(Psr\Http\Server\RequestHandlerInterface@ano nymous)) #4 C:\instance\vendor\slim\slim\Slim\MiddlewareDispat cher.php(65): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Slim\Psr7\Request)) #5 C:\instance\vendor\slim\slim\Slim\App.php(199): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) #6 C:\instance\vendor\slim\slim\Slim\App.php(183): Slim\App->handle(Object(Slim\Psr7\Request)) #7 C:\instance\application\Espo\Core\Api\Starter.php( 76): Slim\App->run() #8 C:\instance\application\Espo\Core\ApplicationRunne rs\Api.php(45): Espo\Core\Api\Starter->start() #9 C:\instance\application\Espo\Core\Application\Runn erRunner.php(84): Espo\Core\ApplicationRunners\Api->run() #10 C:\instance\application\Espo\Core\Application.php( 78): Espo\Core\Application\RunnerRunner->run('Espo\\Core\\Appli...', NULL) #11 C:\instance\public\api\v1\index.php(35): Espo\Core\Application->run('Espo\\Core\\Appli...') #12 {main} Tips: To display error details in HTTP response set "displayErrorDetails" to true in the ErrorHandler constructor.

                  • rabii
                    rabii commented
                    Editing a comment
                    i can't help if i don't see what is your code.

                • #10
                  Yes, Rabii, I understood everything. I made a mistake, thanks anyway.

                  Comment

                  Working...
                  X