mirror of
https://github.com/brunofontes/Memsource-API.git
synced 2025-11-17 02:30:54 -03:00
Transforming into a composer package class
As I should use this into more than one project, it would be better to turn it into a composer package. So I learn how to do that and use it at work at the same time.
This commit is contained in:
34
src/auth.php
Normal file
34
src/auth.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* A very compact and simple Memsource API library
|
||||
*
|
||||
* @author Bruno Fontes <developer@brunofontes.net>
|
||||
* @link https://github.com/brunofontes
|
||||
*/
|
||||
namespace BrunoFontes\Memsource;
|
||||
|
||||
class Auth
|
||||
{
|
||||
protected $base_url;
|
||||
private $_client_id;
|
||||
private $_client_secret;
|
||||
|
||||
function __construct(string $base_url)
|
||||
{
|
||||
$this->base_url = $base_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly login and get a token valid for 24h
|
||||
*
|
||||
* @param string $username Memsource username
|
||||
* @param string $password Memsource password
|
||||
*
|
||||
* @return string Authorization code valid for 24h only
|
||||
*/
|
||||
function login(string $username, string $password)
|
||||
{
|
||||
$authorize_url = $this->base_url . '/oauth/authorize';
|
||||
return $authorize_url . '?response_type=code&client_id=' . $client_id . '&redirect_uri=' . $callback_uri . '&scope=openid';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user