title: Login into Moodle using a token
body: <p>I am trying to figure out a solution on how to login into Moodle from an external API service. I have web services enabled on Moodle. My application uses a API build with Laravel which contains a method to login in directly to Moodle from another webpage. Right now I am able to get the token using GuzzleHTTP POST request like below:</p>
  <pre><code>$tokenBody = [
          'username' =&gt; $userNameString,
          'password' =&gt; $userNamePassString,
          'service' =&gt; 'moodle_mobile_app'
      ];
  
      $getToken = json_decode($callFedAuth-&gt;PostApi(env('TOKEN_URL'), $tokenBody));
  </code></pre>
  <p>Here I am able to get a token and private token like below:</p>
  <pre><code>{
    &quot;token&quot;: &quot;59a30c31b009e8330f175e7c308c8e25&quot;
    &quot;privatetoken&quot;: &quot;4iFZzVhhEZF2blYZXLOhLAr2uEjka8kuHxD9lQd9EQpwFEsNZiyoVcpTPwlfNF2j&quot;
  }
  </code></pre>
  <p>Now how can I use this token to redirect from my API or navigate to the users Moodle home page directly?
  I can make a post request to Moodle login page, but that will only dump the html content back to me and not redirect.</p>