Dynamic setApiCredentials for srmklive/paypal v3 in Laravel 8? - laravel

I'm trying to set up my PayPal config to switch between different seller accounts based on a table I have with client ID and client secret. The documentation says it's possible, but I can't find any example code to help me do it. Any ideas?
$provider = \Srmklive\PayPal\Facades\PayPal::setProvider();
$provider->setApiCredentials(config('paypal')); // Pull values from Config
$token = $provider->getAccessToken();
$provider->setAccessToken($token);

Related

How can create access token for Twilio video conference

Basically I'm backend developer of Laravel. I want to create accessToken for video call using Twilio, front-end is mobile app (Flutter) backend is Laravel.
Twilio developer evangelist here.
As mentioned in these docs, you can generate an access token
on the Testing Tools page of the Twilio Console
with a Twilio helper library
In PHP, that'd look like
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
// Required for all Twilio access tokens
$twilioAccountSid = 'ACxxxxxxxxxxxx';
$twilioApiKey = 'SKxxxxxxxxxxxx';
$twilioApiSecret = 'xxxxxxxxxxxxxx';
// A unique identifier for this user
$identity = "alice";
// The specific Room we'll allow the user to access
$roomName = 'DailyStandup';
// Create access token, which we will serialize and send to the client
$token = new AccessToken($twilioAccountSid, $twilioApiKey, $twilioApiSecret, 3600, $identity);
// Create Video grant
$videoGrant = new VideoGrant();
$videoGrant->setRoom($roomName);
// Add grant to token
$token->addGrant($videoGrant);
// render token to string
echo $token->toJWT();
Depending on what your Twilio Video app looks like, you may be able to do something like what I did in JavaScript here with the Twilio CLI.
Let me know if this helps at all!

Laravel passport: Manually create access token

I'm building an SPA using VueJS and Laravel.
I'm using Laravel passport for logins which works fine.
However I would like the ability to send users magic links to log in with. However I'm not sure how to create an access token without sending a request with the password to the oauth route.
It seems like it should be really easy to do, just inserting the right rows into oauth_access_tokens and oauth_refresh_tokens.
But i've been trawling through the code in the Passport repo and Google results and everything seems way more complicated.
What I would like is be able to do something like this:
$user = User::findFromMagicLink($link);
$token = $user->createAccessToken();
return response()->json(['access_token' => $token->token, 'refresh_token' => $token->refresh_token])
I'm guessing that's not possible otherwise it would be documented somewhere. But if it's something more complicated than that I can't figure it out.
Can anyone point me in the right direction?
Try this You can create access token like
$user = User::findFromMagicLink($link)
$token = $user->createToken('UserToken', ['*']);
//or directly access
$token = $user->createToken('UserToken', ['*'])->accessToken;
For more info Read: Manage personal access token

Google Admin Setttings API connection for .NET

I've been working with the Google directory API for quite some time now.
However, I need to update SSO settings in the admin settings section of Google. Yes, they say it will be deprecated at some point, but according to a google employee, it's going to be a while before a new API is available and then the old one will be removed.
First, if there is a NUGET package out there, please let me know. I can't seem to find anything that works with the admin settings API: https://developers.google.com/admin-sdk/admin-settings/
My first attempt is getting the SSO settings in Google.
I can use postman to pull this information so I know the API works.
However, I'm running into two issues:
How can I authenticate using the service certificate that I use in the apis.google.directory class?
Anticipating, how do I request access to the admin settings? In directory API, I have the scope enum to select from. If I'm making a manual connection to the API I assume I'll need to call this by hand?
Code
var certificate = new X509Certificate2(serviceAccountCertPath,
serviceAccountCertPassword,
X509KeyStorageFlags.Exportable);
// below the scopes are going to get in my way, right? What is the scope process I need to do for this manually?
credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser,
DirectoryService.Scope.AdminDirectoryGroup,
DirectoryService.Scope.AdminDirectoryOrgunit},
User = _szAdminEmail
}.FromCertificate(certificate));
// I'm not seeing anyway to call the above credentials
using (HttpClient client = new HttpClient())
{
// client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
client.BaseAddress = new Uri(#"https://apps-apis.google.com/a/feeds/domain/2.0/[mydomain]/sso/general");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//client.DefaultRequestHeaders.
HttpResponseMessage response = client.GetAsync("api/Values").Result; // Blocking call!
var products = response.Content.ReadAsStringAsync().Result;
return products.ToString();
}
The admin settings API does not appear to support service account authentication you will need to use Oauth2. Admin Settings Oauth
Your not going to be able to use it very easily using the Google .net client library as that library was designed for use with the Google discovery apis. I dont think the Admin Settings API is a discovery api. You might be able to use the old gdata library for it I am not sure if one exists I have not been able to find it on nuget. If you do find it the old gdata library doesn't support oauth2 which means that you will need to use the new library for that and plug in the gdata library after.
I have only done this before using the Google contacts api I have a tutorial here on how i did it it may help you here
Auth
string clientId = "xxxxxx.apps.googleusercontent.com";
string clientSecret = "xxxxx";
string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" }; // view your basic profile info.
try
{
// Use the current Google .net client library to get the Oauth2 stuff.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, "test"
, CancellationToken.None
, new FileDataStore("test")).Result;
// Translate the Oauth permissions to something the old client libray can read
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = credential.Token.AccessToken;
parameters.RefreshToken = credential.Token.RefreshToken;
RunContactsSample(parameters);
If you cant find the gdata library for it you may have better luck just using the library for authencation and then code the rest of the calls yourself. It returns xml not json.

What data can we get from socialite?

I'm using socialite laravel. What data can we get from socialite? Can we get location, phone, etc data from socialite?
according this docs, you can retrieve this user details :
// for All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

Authorizing Application Access to BigQuery without User Interaction, via PHP

I have a website, that does the simple work of fetching an USN from Google BigQuery on the cloud. Now, while accessing each time, I need to have a Google Account and also that particular email-id, should have the "permission" assigned in the "Team tab". I basically want the website to be available to everyone. And i am using PHP, so I need help about the functions that will be useful here.
The best way to build an application that is authorized to access the BigQuery API (as opposed to requiring a user authorization step) is to use OAuth2 service accounts. Essentially, a service account authorization provides certificate-based authorization for "server to server" interactions (such as your server side PHP script interacting with the BigQuery API).
There is documentation for using the Google PHP Client library with service account authorization here.
You have to create a 'service account' through google console and download the private key file (.p12) on your server. And use following code
/**
* setup service client using key file
* #param String $keyFileLoc location of .p12 file provided in google console
* #param String $clientEmail client location provided in google console
*/
function setupServiceClient($keyFileLoc,$clientEmail){
$client = new Google_Client();
$service = new Google_Service_Bigquery($client);
$client->setApplicationName("My Application Name");
$key = file_get_contents($keyFileLoc);
$cred = new Google_Auth_AssertionCredentials(
$clientEmail,
array('https://www.googleapis.com/auth/bigquery'),
$key
);
$this->client->setAssertionCredentials($cred);
return $service;
}

Resources