Automate Google Calendar Access Authorization Code Retrieval - NodeJS - javascript

I'm new to NodeJS and any help will really be appreciated.
I am currently making an application to access a user’s Google Calendar.
Right now I am using the code snippet for NodeJS from the following link, using my project's credentials.
https://developers.google.com/calendar/quickstart/nodejs
After running the script there is a link which directs the user to the Google Login page, where the user can login from a chosen account and then authorize Full Calendar access to the app.
Upon authorizing Calendar access to the application, the user is presented with a Unique code which must be copied into the terminal (prompted by the script) which then generates a token and stores it in token.json.
I want to automate the retrieval of the unique code (generated for the user upon granting access) without the user having to copy the code and paste it in the terminal.
Any help on this would be greatly appreciated!
Also, the page that shows the unique token to be copied and the steps preceding have been shown in the attached screenshots.
Step 1
Step 2
Step 3
Step 4

You need to use a Service Account. They are like "dummy users" which don't require user interaction to be authorized. You will have to grant your users access to the Service Account.
You can follow this guide to set it up:
Open the Service accounts page.
If prompted, select a project, or create a new one.
Click + Create service account.
Under Service account details, type a name, ID, and description for the service account, then click Create.
Optional: Under Service account permissions, select the IAM roles to grant to the service account, then click Continue.
Optional: Under Grant users access to this service account, add the users or groups that are allowed to use and manage the service account.
Click + Create key, then click Create.
Then, use the NodeJS Service Account guide to use the new Credentials.
Instead of Service Accounts, you can also do it by saving the Refresh Token to request new Access Tokens programatically, without user interaction. See this documentation.

Related

Microsoft Graph api - write files to my oneDrive

I am writing a simple web app (Javascript) that includes a form, once the form has been submitted I want to save the data on my oneDrive as a new file. That's all! But for some reason, I cannot accomplish this simple task.
So I want to use oneDrive as my database. but all I can find on the Microsoft Graph API are require a login popup which does not make sense here for me in this case cause the user have nothing to do with that. just want the details will be submitted into my personal oneDrive.
I am using client_credentials flow to generate access token but I keep getting errors like 'Unable to retrieve tenant service info.' or 'Current authenticated context is not valid for this request'
when I try to access the drive API.
I gave all the possible permissions to this app, I am using my personal free Microsoft account
so What am I missing here?
Another issue that I will be happy to know more about is that in my Azure app registration after I register this app and I go to the owner's tab I see this message - 'This app does not belong to any directory, so owners can’t be added to it.' is that might be the problem? how and do I even need to assign this app to a certain directory to use the API for my personal drive?
Also when I am vising the Users section on my Azure portal I see this message - 'You don't have access to this data.'
How is that possible if I do not belong to any organization and I created this azure account??
Thank you in advance, any information here will be helpful cause I am kinda lost.
I am using client_credentials flow to generate access token but I keep
getting errors like 'Unable to retrieve tenant service info.' or
'Current authenticated context is not valid for this request' when I
try to access the drive API.
For this you could use the Code Flow authentication
In this, you will not be needing any tenant information - just the client credentials and access token to access the OneDrive API
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/msa-oauth?view=odsp-graph-online#code-flow
This app does not belong to any directory, so owners can’t be added to
it
If the app had been registered in the converged app portal - you are likely to encounter this. You can you portal access this link and login with your personal account\live account.

Can Custom Authentication be made in Firebase

I am trying to use a 6 digit code to log-in a user.
The code is available for 20 seconds and is unique to every user.
Briefly explained:
User is already logged in on a mobile app
User press the button "Get Unique Code"
Then, user enter the code on a WebPage on his PC
If the code is correct, show data for that user
What am I asking is if there is way to properly authenticate the user who introduces that code correctly given that I have the userID and all the informations about the user?
I can try and "fake log-in" (display all the information for that user when the code is correct) but there are some issues with this and I would like to avoid it.
I am using Firebase Authentication and Firebase Firestore. JavaScript is used for Web.
You can implement any authentication scheme you want by creating a custom provider for Firebase Authentication.
See Authenticate with Firebase in JavaScript Using a Custom Authentication System and Creating Custom Tokens with the Admin SDK.
In this flow you:
Sign in the users yourself.
Create a custom token for those users in a trusted environment, such as a server you control, or Cloud Functions.
Pass that custom token to Firebase Authentication, which can then use it to identify the user, and secure access to Firestore, Storage, and Realtime Database.

Quickblox Javascript SDK Integration

I am using JavaScript SDK for group chat. I have registered users into QuickBlox with whom a user can chat.I have created session and token using API calls and referred the JavaScript SDK sample chat demo. There was no feature of user login. It asked directly username and group name to log in on landing page. So when I only pass the username, it is creating a new user with random login instead of authenticating existing user,and the created dialog is different and it wouldn't create a group chat.
I have utilized following Javascript SDK
https://github.com/QuickBlox/quickblox-javascript-sdk
Looking forward for appropriate solution
We have used special logic for our samples: one browser can create only one user, by the next steps just the user's full_name will be updated. If log out is be, the user will be deleted. And then a next one user can be creating.
It helps us to not creating too much users on backend side.

Implementing Facebook's Graph API without user authentication

I'm newbie to Facebook Graph API and Facebook JavaScript SDK but I'd like to know some things:
Is there any way to put my Access Token in a Open Source application without actually showing it? I'm using GitHub and for security purposes I'd like to make it private.
Can I show my user information without asking the users to Authenticate themselves?
Where in Facebook Developers App can I allow more "scopes" to share publicly? For example, user_photos, user_posts, user_likes, user_status, etc...
These "scopes" that Facebook allows by default are actually the information I'm getting from the user while I'm Authenticating them right?
Just to clarify what I'm trying to do, I want to share things about my Facebook Account through the Facebook Graph API in the gh-pages branch on GitHub, but I don't like the idea of having to authenticate every single user that has access to the page.
I'd like to make my user information public, but don't want to show my access token, because it's Open Source and it can get dangerous eventually.
If you'd like to see my repository and have a better understanding of the project. You can access https://github.com/iszwnc/rye
If I recap:
you don't want to share your app access token (good!),
you don't want your users to authenticate.
Basically, you can't hide your token and let your users query Facebook directly. You need some server-side code on a machine that would be the only one reaching Facebook. Your server would play the role of an interface between Facebook and your users. So you will have to:
do the API calls from a server using server-side code (i.e. Node.js),
save the information you want in a database. This is optional but better to avoid the same information to be retrieved multiple times, thus avoiding your future 100 users to (voluntarily or not) reach your app API limit.
let the users query your server using some client-side code (i.e. AngularJS) in order to retrieve what you and only you know (remember, you own the token).
About Github, don't share your token on it. People can generate their own token if they want to run your app. Here are several suggestions:
Add your token to an environment variable which you can set just before launching the app (don't forget to mention that in your README),
Add your token to a file:
Create a credentials.js file that contains an empty token:
// Please use your own token
var APP_TOKEN = '';
Commit the file to Github,
Have a .gitignore file that contains the credentials.js,
var APP_TOKEN = 'now-you-can-put-your-token-here';
Good luck with your project, it looks exciting :-)

How can I hook up facebook connect with our site's login?

I want to implement something similar to what Digg has done.
When the user logs in for the first time, I want it to force them to create an account on my site.
More importantly I want to know how to log a user into my site when they login with facebook connect. If they login with facebook connect, they still haven't provided me the password to their account on my site, so I can't use username/password to log them into my site. How do they do this on Digg or sites similar to this?
Facebook's process flow can definitely be a bit confusing. Take a step back from the details and the API, and look at the overall flow here:
Facebook Connect will tell you that a user is logged into Facebook, and give you their Facebook ID. You can validate that ID against Facebook using Facebook Connect to make sure it is properly logged in. Once this is done, you don't need a user name and password. As long as you trust that Facebook has authenticated the person properly, they are the only ones that can come to your site using that Facebook ID. That is enough information to start an authenticated session based around a local account that is associated with that ID.
The process you should follow is like this:
User logs in to your site with
Facebook Connect for the first time
You notice that you don't have a local account associated with that
Facebook ID, and prompt them to
enter local account information
You save that information along with their Facebook ID
The next time you see that Facebook ID (and validate that it is
logged into Facebook using the
Facebook API), you can start up a
local session using the associated
account.
Basically you end up with two separate methods of authentication: a Facebook Connect ID check, or the regular username/password login on your site. Either one should have the end result of starting a local authenticated session.
Hope that helps.

Categories

Resources