How to do a Login woth a google account in JMeter - authentication

I try to login into an application that uses a login with Google Accounts. I try with the script recorder but it doesn't work.

Most probably login via Google Account is implemented using OAuth protocol and this is not something you can record and replay. Actually you don't need to load test the logging in process itself as it mostly being performed on Google side.
In order to be authenticated you need to supply correct Authorization Bearer token via JMeter's HTTP Header Manager. The token can be obtained using one of the following ways:
By recording (look for Authentication: Bearer token in the HTTP Header Manager
Using real browser from the WebDriver Sampler and once you're logged in - copy session information from browser into JMeter
From the Google Console if you have permissions
By performing full authentication process using i.e. OAuth Client Library for Java from JSR223 Sampler
See How to Run Performance Tests on OAuth Secured Apps with JMeter article for more detailed explanation on each of the approaches.

Related

Fetch Oauth 2.0 token for Authorisation Code Flow

I can trying to fetch the oauth2 token from token url .I am using authorisation code flow in Oauth2 .
For the token url call ,mandatory parameter is code.
So I need to do a get call on authorization url and get the code.
In postman while doing the authorization call I am getting redirect page(ui to enter credentials)
.Is there any other way to fetch the token using this flow without going through ui as this is specifically testing api
This is for API Automation Testing.
Microsoft documentation attached - https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
It is not easy in OAuth to get a token for a user for automated test scenarios. Authorization Code Flow requires redirects to be followed and complex slow code
Usually you do not want to test Azure AD itself because it is not your code.
One simpler option for automated tests is to use Resource Owner Password Grant to get a token as a user via a simple HTTPS POST. It is not recommended to use this in real UIs though.

How to automate authentication flow for Firebase with Google Provider using REST API?

I have a system that is using Firebase authentication with Google provider. I have an issue with automating integration tests for API. Tests are represented by a bunch of HTTP requests (Postman collections). I need to do some steps before tests to get a token from Firebase.
Only solution I can see is to add refresh token to the tests and call Refresh token endpoint to get a new token. Not sure how long will the refresh token live. Doesn't look like a good solution. E2E frameworks like Selenium are not an option.
What I want to achieve in the ideal scenario:
The input for the test is username/password for Google account and maybe settings pointing to the correct Firebase project. I need to perform some
magic HTTP requests (without user interaction) to get Firebase token back.
Does anyone knows if that is feasible? If not - how this flows can be automated without Selenium?

How to create load tests with jmeter when our website has no authorization with create user ... but it has authorization via social networks

How to create load tests with jmeter when our website has no authorization with create user ... but it has authorization via social networks?
In the majority of cases authorization via social networks is being done using OAuth protocol, the implementation differs depending on social network, i.e.:
Facebook: Manually Build a Login Flow
Twitter: Authentication
etc.
So basically your test needs to contain Authorization: Bearer token (you can add it using HTTP Header Manager).
If you're lucky enough your application may rely on "permanent" tokens or tokens living long enough so you could complete your testing. Otherwise you will have to obtain tokens somehow and even refresh them if they expire prior to your test end i.e. in case of Soak Test
You can find generic guidance steps in the How to Run Performance Tests on OAuth Secured Apps with JMeter article.

How can I test the Microsoft Authentication process using automation?

I am new to Microsoft Graph Framework. I recently developed a web application with Graph API's integration.
The first time browsing to the page on my app, it redirects the user to Microsoft app login page and prompt for credentials. Once authentication successful then I use the authentication token to get the user's emails and do post processing on those emails.
However, I need to write tests to see if the token is being persisted properly and for the subsequent processing on emails. All my tests are automated tests that are run on jenkins which is not set up to run with a browser. And without having the authentication token, I am unable to test the downstream process. Is there a way to get the token through an API without requiring a browser/user intervention?
For automated tests running in Jenkins, you probably want to use an auth flow that doesn't require the user to login. Please see the documentation page on Getting auth tokens without a user for detailed information.
In summary, you can register an app on the App Registration site and add application permissions like User.Read.All. Since the goal is to get tokens that work without a user login, you'll need to grant your app access to run as a service by getting administrator consent. After that one time setup, you can then easily request tokens by POSTing to the token endpoint with your app info and secret.
Perhaps you could use the username/password authentication flow, where your test doesn't go through the normal interactive experience.
You need to create a UserCredential and use that to acquire a token.
UserCredential uc = new UserCredential(user, password);
public Task<AuthenticationResult> AcquireTokenAsync(
string resource, string clientId, UserCredential userCredential);

obtain a Google OAuth 2.0 Bearer token from a client and secret [duplicate]

This question already has answers here:
How do I authorise an app (web or installed) without user intervention?
(2 answers)
Closed 5 years ago.
I have a client id and client secret for my Google Container Engine app obtained via Credentials and I just want to do some local testing of the JSON API endpoints.
How can I convert this into a Bearer token so that I can just get some work done? Is there a Google page where I provide these things and get a token that I can use in my app?
I don't want to have to write an entire OAuth handling mechanism at this point in time (which would use the flow described in oauthplayground). It's an app to be run only for my account, in headless mode, on a trusted machine, to manage my cluster.
NOTE: must not require any proprietary software installations (e.g. the Google SDK).
Google provides an API Client Library for Java, which itself depends on an OAuth client library.
For the project of 9Cards launcher for Android, within the back-end, we had to use this library to fetch applications usage statistics from Google Analytics. In our code, because it is a case of "server to server" authentication, we use a Service Account's credentials. The code issues a request from Google a short-lived OAuth2 Auth Token. The library may provide similar features if you use a Client-ID and Client-Secret.
Regarding the issue of licenses, the library is published under Apache License v2, so in that regard it is not too proprietary.
I have a client id and client secret for my Google Container Engine app obtained via Credentials and I just want to do some local testing of the JSON API endpoints.
Good start. I guess by "the JSON API endpoints" you mean the Google APIS. Make sure you created OAuth Client IDs and not one of the other options.
How can I convert this into a Bearer token so that I can just get some work done? Is there a Google page where I provide these things and get a token that I can use in my app?
Yes the OAuth Playground will do that for you. The detailed steps and sample code to consume the token is at How do I authorise an app (web or installed) without user intervention? (canonical ?)
I don't want to have to write an entire OAuth handling mechanism at this point in time (which would use the flow described in oauthplayground).
Follow the steps linked to above and you will see that you don't need to write any code at all. Once you have the refresh token (a one time procedure), you're all set. I exaggerate slightly, you do need one line of code to post the refresh token to the Google Oauth endpoint to fetch an access token. See the bottom of the linked answer for an example. Or you could just compose a curl to do it from the command line and put the Access Token into an environment variable.
I just wanted to avoid the whole thing and get a code printed on the screen
A bit like https://youtu.be/hfWe1gPCnzc?t=198