In a project I am provided with API endpoints from a Firebase DB.
To retrieve data I authenticate a user with email and password (https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-email-password) and then sign every API call with the token. (These users are set up in Firebase DB)
Now one of the API endpoints returns Firebase Storage objects like this:
"fileReferences": [
{
"id": "",
"name": "images\/-s0m31D\/picture.jpg",
"mediaLink": "https:\/\/www.googleapis.com\/download\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg?generation=1537959346600572&alt=media",
"selfLink": "https:\/\/www.googleapis.com\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg",
"updated": 1537959346,
"size": 7759448
}
],
when I try to access fileReferences.0.mediaLink, I get an auth error.
If I send my token along with the request to mediaLink I have no luck either (https://cloud.google.com/storage/docs/downloading-objects#download-object-json)
I tried to use the Google API PHP client https://github.com/googleapis/google-api-php-client, but had no idea how I setup the new Google_Client() (I already have my auth token and I expected it to work somehow)
$client = new \Google_Client();
$client->setAccessToken(['access_token' => $token]);
How can I access the media files with my existing auth token? (or do I need a different one?)
To handle the files, I would like to use https://github.com/googleapis/google-api-php-client how can I make that work? Any hint is appreciated
Edit: I got some results in debugging the JavaScript SDK
"All" the SDK does is creating the following URL Schema
printf('https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/%s', urlencode('projects/-id/logo.png'));
//http[s]://firebasestorage.googleapis.com/<api-version>/b/<bucket>/o/<object-path>
You have to sign the call to https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png with your Auth Bearer token header![1]
This returns meta data like this:
{
"name": "projects/-id/logo.png",
"bucket": "bucket.appspot.com",
"generation": "1537960188874518",
"metageneration": "1",
"contentType": "image/png",
"timeCreated": "2018-09-26T11:09:48.874Z",
"updated": "2018-09-26T11:09:48.874Z",
"storageClass": "STANDARD",
"size": "40437",
"md5Hash": "MxkOU+6feyYtdEAgKbDgp5A==",
"contentEncoding": "identity",
"contentDisposition": "inline; filename*=utf-8''logo.png",
"crc32c": "o89Y9dQ==",
"etag": "CJae8pXE2N0CEAE=",
"downloadTokens": "32c339ff9-7e4a-42a2-890a-428f8f45d378"
}
To publicly share your image, add ?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
You don't need the token, if you send the Auth Header!
I couldn't find any mention of firebase or how to deal with my authentication in https://github.com/googleapis/google-api-php-client, so I have no idea if this would have helped me. But I got down to the basics...
Hope this helps somebody and any clearification is greatly appreciated.
QUESTION for me to better understand this all:
What are mediaLink and selfLink pointing to?
[1] if the access to storage is public you don't need to sign it.
Related
I want to create contacts with outlook in my application.Firstly, I get into this url below
https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
I hope this is an old way to get the token,so I am
https://login.microsoftonline.com/daa825ce-e4fb-40d2-b2e6-3a2f25e62b7c/oauth2/token?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
So I get this error below.
http://prntscr.com/p4mb2c
To create contacts, you should call
POST https://graph.microsoft.com/v1.0/me/contacts
Content-type: application/json
{
"givenName": "Pavel",
"surname": "Bansky",
"emailAddresses": [
{
"address": "pavelb#fabrikam.onmicrosoft.com",
"name": "Pavel Bansky"
}
],
"businessPhones": [
"+1 732 555 0102"
]
}
You can follow this document to get the access token. Remember to grant your application Contacts.ReadWrite permission.
The scope in steps2&step3 should be https://graph.microsoft.com/Contacts.ReadWrite
Update:
To use personal account, you need to set the supported account type like below
And the authorize endpoint should use common, not the specified tenant.
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=562855f4-f3dd-40bb-b829-515ccb96ff3f
&response_type=code
&redirect_uri=http://localhost
&response_mode=fragment
&scope=https://graph.microsoft.com/Contacts.ReadWrite
&state=12345
Also the token endpoint.
https://login.microsoftonline.com/common/oauth2/v2.0/token
I have a firebase project and I use a simple web page to login to firebase with username and password just like below...
firebase.auth().signInWithEmailAndPassword
('test.account#gmail.com', 'password').
catch(function (error) {
});
And I got the response like below...
{
"kind": "identitytoolkit#VerifyPasswordResponse",
"localId": "iWFUfdgdsdfsC2",
"email": "test.account#gmail.com",
"displayName": "",
"idToken": "whfGUWiyDE74HsnwN5ZkJn7gX",
"registered": true,
"refreshToken": "SZaG1tmzkgn5EImQ_nRj8",
"expiresIn": "3600"
}
I followed "kreait/firebase-bundle". But didn't get any idea.
My question is is there any way to verify the signed user from symfony backend ?
Someone please help me...
I having problem that when user logged in i get a token and i am building apis and that token i need to pass on every request in postman:
My Response when i got current logged in user;
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTI3LjAuMC4xOjgwMDAvYXBpL2xvZ2luIiwiaWF0IjoxNTIzMjY5OTUxLCJleHAiOjE1MjMzMDU5NTEsIm5iZiI6MTUyMzI2OTk1MSwianRpIjoiSlNXa0hPbGxvOWdQNnRkNCIsInN1YiI6MiwicHJ2IjoiODdlMGFmMWVmOWZkMTU4MTJmZGVjOTcxNTNhMTRlMGIwNDc1NDZhYSJ9.Dt9fLL4d1mgwU7LMCNOeBoITs4Q0mAIeG07aCjRgaNM",
"currentUser": {
"id": 2,
"name": "Shahzad Hussain Shah",
"email": "shahzad.hussain#vaivaltech.com",
"created_at": "2018-04-09 10:22:18",
"updated_at": "2018-04-09 10:22:18"
}
}
and this token i need to pass everytime and if shut down my pc and on again then i have to login my user again so that i got a new token and then i can start my work with that token:
Here i want to avoid this token and when my website comes to live what will be the solution of tproblem:
When i used Auth::user()->id; it says trying to get property of non object then i need to pass the token: but here i want i just used Auth::user(); and it should pick id of current logged in user:
Any help will be highly appreciated!
i just need some help with Twitters' API
I used the sign in with twitter flow to get the tokens needed to make calls to the API, there weren't any problems with the implementation, and so far I have got both oauth_token and oauth_token_secret so I think I have what I need to use the API.
The problem is about the last method which the documentation said about verif credentials, I am supposed to use that GET method to get a json with information about the user which has just logged into twitter by my app, however, Twitter docu doesn't mention anything about what parameters I need to pass or what headers, just the url.
I used php curl to make the calls to the API, do you know what parameters I need to pass to the API to finally get the json?
Here you have the link to the API docu:
https://dev.twitter.com/rest/reference/get/account/verify_credentials
Thanks in advance.
No params, just the 'Authorization' header.
Use the "OAuth Signature Generator" on the link you included to generate a test request and confirm yourself.
You just need to properly sign the request. This provides the context including the user, since it implicitly includes details about your request, the client secret, the user token etc.
$ oksocial https://api.twitter.com/1.1/account/verify_credentials.json
{
"id": 999999,
"id_str": "999999",
"name": "Bobby Bonson",
"screen_name": "xxxx",
"location": "CA",
"description": "...",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 699,
"friends_count": 631,
"listed_count": 34,
I am working with Github now.How can i suppose to get the "OAuth token" for github login user.Now i have the Data like client_id,Client Secret,access_toke(these all data getting after login to github only).how can i get the OAuth token through the above data.
I got oauth toke through command line like:
[root#localhost Dinesh]# curl -u 'DineshGK' -d '{"scopes":["repo"],"note":"Help example"}' https://api.github.com/authorizationsEnter host password for user 'DineshGK':
[root#localhost Dinesh]# curl https://api.github.com/authorizations --user "DineshGK" --data '{"scopes":["user"], "client_id":"...", "client_secret":"..."}'
Enter host password for user 'DineshGK':
{
"id": 2300973,
"url": "https://api.github.com/authorizations/2300973",
"app": {
"name": "SenchaPlayground",
"url": "http://192.168.1.56/OldPlayground/"
},
****"token": "..."**,**
"note": null,
"note_url": null,
"created_at": "2013-04-16T07:34:21Z",
"updated_at": "2013-04-16T07:34:21Z",
"scopes": [
"user"
]
}
I want that Highlighted token pragmatically(using JS/PHP)..
Can any one help...
Thanks in advance ....
Please edit your question to remove your "client_id", and the token returned. Also, please go to your app settings and get a new "client_secret". None of that information should ever be made public to ANYONE.
Now, if your intent is to use cURL from JavaScript or PHP, you're going to have a very bad time. I would look into the how to make HTTP/1.1 requests in each and check out some of the existing libraries for either PHP or JavaScript that wrap the API for you. With those in hand (having never used any of them in all candor) you should probably receive something akin to a Hash or some other data structure to be able to retrieve that information. If you read their documentation you'll do a lot better than someone telling you what to do who has never used any of those libraries.
You can't completely automate this process, the user must be involved to manually grant access to your application. That said, Temboo simplifies the OAuth process for GitHub by breaking it into two steps:
Generate an authorization URL that you can display to your user. This allows the user to authorize you to use their GitHub account. The first step also generates the callback URL you'll need for the second step of the process.
Retrieve an access token once the user has granted access to your application.
Full details on how Temboo simplifies GitHub OAuth (using PHP) can be found here.
(Full disclosure: I work at Temboo)