Closed Duncan-dev1 closed 3 years ago
To generate the oauth credentials all you need is a controller like this.
<?php
namespace App\Http\Controllers;
use AylesSoftware\XeroLaravel\XeroOAuth;
class XeroOAuthController extends Controller
{
public function __invoke(XeroOAuth $xeroOAuth)
{
return $xeroOAuth->flow();
}
}
You can then create a route.
Route::get('xero-oauth', 'XeroOAuthController');
Then you can navigate to /xero-oauth this will redirect you to xero for authentication. After Xero will redirect back.
Make sure you have XERO_REDIRECT_URL=
set to /xero-oauth
Thank you for the prompt response,i didnt have my XERO_REDIRECT_URL
same as my route,after doing that i know get an error Calcinai\OAuth2\Client\Provider\Exception\XeroProviderException
Forbidden where could this be coming from
Do you have these .env vars set?
XERO_CLIENT_ID=
XERO_CLIENT_SECRET=
Have you registered the app with Xero?
Yes i have those,also my xero app's redirect is same as my XERO_REDIRECT_URL
,i am serving my app using php artisan serve for my localhost
What is the exception message?
Below is my log `[2021-05-08 06:44:57] local.ERROR: Forbidden {"userId":1,"exception":"[object] (Calcinai\OAuth2\Client\Provider\Exception\XeroProviderException(code: 403): Forbidden at C:\xampp\htdocs\laravuex\vendor\calcinai\oauth2-xero\src\Provider\Xero.php:132) [stacktrace]
<T...')
"} `
Checkout the scopes in the config. Looks like you don't have access to something.
You can publish the config by using
php artisan vendor:publish --provider="AylesSoftware\XeroLaravel\ServiceProvider"
Sorry to bother you this much,i have those already ` <?php
return [ // https://developer.xero.com/documentation/oauth2/scopes 'scope' => 'openid email profile accounting.settings accounting.transactions offline_access',
'redirect_after_authorization_url' => '/home',
'redirect_url' => env('XERO_REDIRECT_URL'),
'client_id' => env('XERO_CLIENT_ID'),
'client_secret' => env('XERO_CLIENT_SECRET'),
]; `
This would be an overkill but could you have 3 or 4 mins so that i can show you what i have in my comp,maybe through google meet?I desperately need some help
If you can get exception message coming back from Xero, that is being thrown by XeroProviderException
, that will point you in the right direction.
The exception message might even come back in the url.
yes i am getting this Calcinai\OAuth2\Client\Provider\Exception\XeroProviderException Forbidden
means at least the authflow is going all the way.i am also using a demo company,which i suppose should not be a problem
What is the full url when you get that exception?
my url http://127.0.0.1:8000/xero-oauth?code=c25a6e2f866075db04c4c65d62f927be75725c876c352eb6a02344925c64a2e6&scope=openid%20email%20profile%20accounting.settings%20accounting.transactions&state=ab72416c432a371113ce1b948466d1ee&session_state=rO13lSIifv-exe77WRwIYCjG9TcYqyXEQyiQr5j1f9E.88b6fd12b6036d5116070659e8f9348e
To generate the oauth credentials all you need is a controller like this.
<?php namespace App\Http\Controllers; use AylesSoftware\XeroLaravel\XeroOAuth; class XeroOAuthController extends Controller { public function __invoke(XeroOAuth $xeroOAuth) { return $xeroOAuth->flow(); } }
You can then create a route.
Route::get('xero-oauth', 'XeroOAuthController');
Then you can navigate to /xero-oauth this will redirect you to xero for authentication. After Xero will redirect back.
Make sure you have
XERO_REDIRECT_URL=
set to /xero-oauth
Just for clarification,the XERO_REDIRECT_URL=
should be to the route that started the oauth process,in this case xero-oauth?
For example
XERO_REDIRECT_URL=https://website.test/xero-oauth
Yes i have it like that,would uninstall and then reinstalling the package help?
I can give you my anydesk you see whats going on my end,if you have a minute
The issue was that xero requires you to use https instead of http.thank you
Hi there,i am currently using this package to integrate xero,which i am new to with laravel. i am stuck at the auth flow though,directing users to choose the tenant works fine and i get a redirect with a code and matching status as the the one in the request.The request has
%26state%3D44e732003592baea709dd2e85f94d3a4%
and the redirect has&state=44e732003592baea709dd2e85f94d3a4&
which i suppose i fine.I have a problem with the exchange of code for access token though.i thought of calling the generate function inside the flow function that is invoked at the XeroAuthController as per the docs .`<?phpnamespace AylesSoftware\XeroLaravel;
use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use AylesSoftware\XeroLaravel\Entities\XeroAccess; use Calcinai\OAuth2\Client\Provider\Xero as XeroOAuthClient;
class XeroOAuth { public $request;
} ` What am i missing and how should i go about generating and storing the credentials in the db