I am trying to create a log in using AWS Cognito
I have setup the federated identities, and added a user pool, and added a email address to the user pool.
I have created some PHP code to getID and to OpenIDToken.
Which is a good start, but this only works in an unauthenticated setup I want to be able to log a user in using the username and password that was given to them .
I can't seem to find any information that I am able to understand to get this to work.
How do I go about logging a user in from a user Pool using PHP and AWS API v3?
Here is the code I have now:
include "vendor/autoload.php";
use Aws\CognitoIdentity\CognitoIdentityClient;
$identityClient = CognitoIdentityClient::factory(array(
'region' => 'us-east-1',
'version'=>'latest',
'credentials' => array(
'key' => $awsuser,
'secret' => $awssecret,
)
));
$idResp = $identityClient->getId(array(
'AccountId' => 'XXXXXXXXXXX',
'IdentityPoolId' => 'us-east-1:0689a59d-d385-4f80-88ce-XXXXXXXXXXXX',
));
$identityId = $idResp["IdentityId"];
echo $identityId;
$tokenResp = $identityClient->getOpenIdToken(array(
'IdentityId' => $identityId
));
$token = $tokenResp["Token"];
echo $token;
Sorry for the confusion. When you sign in with Cognito User Pools, you'll get a few tokens. One of which is the id token, you'll need to pass that in to the Cognito federated identities client logins map with 'cognito-idp..amazonaws.com/' as the key. More information is available in the developer guide. You might also find this blog post useful, it has examples of how to set logins using the PHP SDK.
Related
I want to use the Microsoft Graph API on my application (which is actually on development).
I use fullcalendar js on my application (laravel 8) and when a user create an event on my application I want the same event create on his outlook calendar.
I want that the user connected on my application has only the right to access his outlook calendar (not all organization users calendar). In order to restrict this I understand that I have to use delegated autorizations and not applications autorizations.
First I would like to get an access token in order to use the API.
To do this I use oauth2 and guzzle :
$url = 'https://login.microsoftonline.com/' . env('MS_TENANT_ID'). '/oauth2/v2.0/token?api-version=1.0';
$tokenCall = Http::asForm()->post($url, [
'grant_type' => 'client_credentials',
'client_id' => env('MS_CLIENT_ID'),
'client_secret' => env('MS_CLIENT_SECRET'),
'scope' => 'https://graph.microsoft.com/.default',
'username' => 'xxx.xxx#xxx.com',
'password' => 'xxxxxxxx',
]);
$accessToken = json_decode($tokenCall->getBody()->getContents());
I obtain a token but when I inspect it with jwt.io, it appears that I haven't scopes in it (scp).
Do you know why it doesn't appears?
EDIT:
It appears that I use an application authentication and not a delegated authentication (for user).
So I change the 'grant_type' parameters for 'password' instead of 'client_credentials'.
But it throws me another error :
invalid_grant
AADSTS65001: The user or administrator has not consented to use the application with ID 'xxxxxxxxxxxxxxxxxxxxxxxx' named 'Graph PHP'. Send an interactive authorization request for this user and resource.
I read that in an delegated authentication I have to call the authorize point before the token point.
To do this I have to define a Redirect URI on my application on Azure. Unfortunately I made development on a local server (not localhost) which haven't SSL. Azure dosen't allow the Redirect URI to be on http except for localhost...
Is someone have already face this problem?
I'm using y0lk package to help me with OAuth1 and ETSY App, I managed to get the temporary credentials, but can't get my hand on Access tokens.
here's what I do :
$client = new Etsy([
'identifier' => '*********************',
'secret' => '*********',
'scope' => 'listings_r transactions_r',
'callback_uri' => 'http://*********.loc/slider/'
]);
$tempCred = $client->getTemporaryCredentials();
$tmpSecret = $tempCred->getSecret();
$tmpId = $tempCred->getIdentifier();
// Redirect to Etsy Autorisation login page
$redirect_url = $client->getAuthorizationUrl($tempCred);
$accessTokens = $client->getTokenCredentials($tempCred, $tmpId, $_GET['oauth_verifier']);
Ok, I don't know how to do, because to obtain the oauth verifier ( and do the $_GET['oauth_verifier']), I have to go by the login page, and then, to get the access token, I need my temp credentials, but to get then I 'll have to go again by new Etsy and this is why I always got the token revoked error..
I'm beginner, in PHP and with API, if someone see other mistakes in my way to do this, feel free to point them out for me :)
Thank you for your time.
Is it possible to send automatic tweets from laravel like user.
User must be logged by my twitter API, and then can I send tweet as him?Of course he must accept this action. I must know when user tweets my page.
Can it work like facebook share? Is there tools for this?
Sorry for my english.
Thanks for all answer.
PS.
I do not mean this package http://vegibit.com/send-a-tweet-with-laravel/ .
I need send tweets to user table.
I have found the ThuJohn package to be the winner at this type of work.
https://github.com/thujohn/twitter
Simple to use with various options, such as
Send a tweet realtime without media:
Route::get('/send-tweet-no-media', function()
{
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'format' => 'json']);
});
Send a tweet realtime with media:
Route::get('/send-tweet-with-media', function()
{
$uploaded_media = Twitter::uploadMedia(['media' => File::get(public_path('filename.jpg'))]);
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'media_ids' => $uploaded_media->media_id_string]);
});
You can also do various other things, such as login, You can take it an extra level and easily store the users token & secret to your users table and do scheduled posts.
Once you have stored the users token & secret you can tweet scheduled posted for them like this:
//Get the Users token & from your User Table (or where ever you stored them)
$token = $user->token;
$secret = $user->secret;
//This line resets the token & secret with the users
Twitter::reconfig(['token' => $token, 'secret' => $secret]);
//This line posts the tweet as the user
Twitter::postTweet(['status' => 'test', 'format' => 'json']);
Use this https://twitteroauth.com/ package.
Push in your console composer require abraham/twitteroauth
When all installed then you should add
use Abraham\TwitterOAuth\TwitterOAuth; to your class.
Now in function you must create connection with your api.
$connection = new TwitterOAuth(
CONSUMER_KEY, // Information about your twitter API
CONSUMER_SECRET, // Information about your twitter API
$access_token, // You get token from user, when him sigin to your app by twitter api
$access_token_secret// You get tokenSecret from user, when him sigin to your app by twitter api
);
If you created connection then you can send post as user.
For example:
$connection->post("statuses/update", ["status" => "My first post!"]);
I am the owner and admin of a LinkedIn company page: https://www.linkedin.com/company/{id}/.
I want to connect to LinkedIn and get return a JSON-feed with latest 10 posts on my company wall to display on my website so I touch on the service https://api.linkedin.com/v1/companies/{id}/updates?format=json.
The JSON is outputted in linkedin.php. This file is then included in my web page, say index.php.
I have registrered an app at https://developer.linkedin.com. I have entered my Client ID and Client Secret in PHP-LinkedIn-SDK available here https://github.com/ashwinks/PHP-LinkedIn-SDK.
I followed the developer documentation I need to authenticate first. When I run linkedin.php I am redirected to sign into my LinkedIn profile. I have to finish this step in order to touch the service above.
With the current solution my users will have to login into LinkedIn when they access my website.
How can I access a list of my company's LinkedIn posts without prompting my users to sign in?
Thanks.
1. Generate your access token
Follow the documentation https://github.com/ashwinks/PHP-LinkedIn-SDK to create a login link.
2. Save your access token
Once you get it, it will be available for 60 days. Save it into your database.
3. Fetch your company posts
You can use the same access token to fetch company contents
$li = new LinkedIn(...);
$li->setAccessToken(YOUR_ACCESS_TOKEN);
$posts = $li->get('/companies/YOUR_COMPANY_ID/updates/');
4. Manage response
Cache or display the response after parsing it.
Hope that helps,
Use https://packagist.org/packages/linkedinapi/linkedin
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere'
)
);
//Get the login URL - this accepts an array of SCOPES
$url = $li->getLoginUrl(
array(
LinkedIn::SCOPE_BASIC_PROFILE,
LinkedIn::SCOPE_EMAIL_ADDRESS,
LinkedIn::SCOPE_NETWORK
)
);
/*LinkedIn will redirect to 'callback_url' with an access token as the 'code' parameter. You might want to store the token in your session so the user doesn't have to log in again*/
$token = $li->getAccessToken($_REQUEST['code']);
$token_expires = $li->getAccessTokenExpiration();
//Make a request to the API
$info = $li->get('/people/~:(first-name,last-name,positions)');
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere',
'curl_options' => array(
CURLOPT_PROXY => '127.0.0.1:80',
),
)
)
I am able to get the Records of the UserVoice by calling and Unauthorized Requests but now i want to create and Update things in which i need OAuth but i am unable to find the UserVoice's PHP Implementation of OAuth and Create/Update/Delete with UserVoice API is there anyone can guide me how to Implement such thing??
We have quite recently worked on this and released an OAuth-based library which makes it a bit easier to access UserVoice API from a PHP version 5 application.
An example on how to create a ticket using an access token for user#example.com:
<?php
require_once('vendor/autoload.php'); // Using Composer
$client = new \UserVoice\Client('subdomain-name', 'API KEY', 'API SECRET');
$access_token = $client->login_as('user#example.com');
$result = $access_token->post("/api/v1/tickets", array(
'ticket' => array(
'state' => 'open',
'subject' => 'PHP SDK',
'message' => "Would you have any OAuth example for PHP?"
)
));
?>
Despite the fact that the library is still under development, I believe it's already useful to you. See the blog post and more examples like responding to tickets as an account owner at:
http://developer.uservoice.com/docs/api/php-sdk/