Not able to get through webseal authentication using rest-assured - rest-assured

working on an automation assignment and i am trying to test a web service hosted on a webseal server. the issue is i have pretty my tried every method in rest assured to get to the response json but what i am getting is the authentication screen html.
here is some of my non working code. what i was expecting it the json but no matter what authentication method i run i get the webseal's authentication page only.
private String serviceTestGET(WebServiceTest serviceTest) {
System.out.println("Credential : " + userName + " -- " + password);
// RestAssured.
// RestAssured.authentication = basic(userName, password);
// RestAssured.authentication = digest(userId, password);
// RestAssured.authentication = oauth(consumerKey, consumerSecret,
// accessToken, secretToken);//form(userName, password);
// RestAssured.authentication = form(userId, password, config);
RestAssured.useRelaxedHTTPSValidation();
return given().get(serviceTest.getEntryPoint()).asString();
}

I have found the answer after googling a bit.
there are few things we have to consider that webseal is going to authenticate the request by throwing back a authentication form. once that form is authenticated its expected that you will use the same session(cookies) to access the application behind the webseal server.
so here is my working code
System.out.println("Credentials : " + username + " - " + password);
RestAssured.useRelaxedHTTPSValidation();
SessionFilter sessionFilter = new SessionFilter();
Map<String,String> cookies = given().
filter(sessionFilter).
param("username", username).
param("password", password).
param("login-form-type", "pwd").
expect().
statusCode(200).
when().
post("https://your-web-seal-server/pkmslogin.form").getCookies();
Reporter.log("Server Authenticated");
return given().filter(sessionFilter).cookies(cookies).expect().statusCode(200).
when().get(serviceTest.getEntryPoint()).asString();

Related

How to Configure Jenkins Login in iPad using Unity

I had installed Jenkins in network and making build successfully.
I want to have authentication for my iPad app, developed with unity. I searched the plugin respective to this, but i can't find it. whether this can be attained by means of plugin or otherways?
As i need to login into my jenkins and afterward use the data of pipelines and all in my app accessed through URL so need login first.
Please do let me know the ways to do. Thanks in advance
After some searching and all i found the solution for this and i used following code to check authentication.
public void TryLogin ()
{
UnityWebRequest req = UnityWebRequest.Get ("Your jenkins login url of network");
req.method = "GET";
req.SetRequestHeader("Authorization", "Basic " + Convert.ToBase64String (Encoding.UTF8.GetBytes ("jenkinsId:jenkinsPassword")));
StartCoroutine (WaitForLoginRequest (req));
}
IEnumerator WaitForLoginRequest(UnityWebRequest req)
{
yield return req.Send ();
if (req.isError)
{
Debug.Log ("WWW Error: " + req.error);
}
else
{
Debug.Log("WWW Ok!:");
string response = Encoding.UTF8.GetString (req.downloadHandler.data);
Debug.Log ("Response code = " + req.responseCode);
Debug.Log ("String = " + response);
}
}
And check the response code for authentication.

Venmo Oauth 2.0 Using Ionic Framework - 400 Bad Request Error

I am currently trying to login to my app that is built on Ionic Framework using Venmo's Oauth API. I am attempting to use the Server Side Flow so that I can have a longer term access token. I am able to receive a code and set it to a requestToken variable.
However, when I attempt to post to "https://api.venmo.com/v1/oauth/access_token" with my Client Id, Client Secret, and Request Token, I get the following error alert: "ERROR: [object Object]".
In checking my console, I see that the error is a 400 Bad Request error coming on my post request, although it does appear that I have a valid request token. The error message is as follows: "Failed to load resource: the server responded with a status of 400 (Bad Request)".
Below is the code of the login function I am using to login via Venmo's Oauth API:
//VENMO SERVER SIDE API FUNCTION
var requestToken = "";
var accessToken = "";
var clientId = "CLIENT_ID_HERE";
var clientSecret = "CLIENT_SECRET_HERE";
$scope.login = function() {
var ref = window.open('https://api.venmo.com/v1/oauth/authorize?client_id=' + clientId + '&scope=make_payments%20access_profile%20access_friends&response_type=code');
ref.addEventListener('loadstart', function(event) {
if ((event.url).startsWith("http://localhost/callback")) {
requestToken = (event.url).split("?code=")[1];
console.log("Request Token = " + requestToken);
$http({
method: "post",
url: "https://api.venmo.com/v1/oauth/access_token",
data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&code=" + requestToken
})
.success(function(data) {
accessToken = data.access_token;
$location.path("/make-bet");
})
.error(function(data, status) {
alert("ERROR: " + data);
});
ref.close();
}
});
}
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function(str) {
return this.indexOf(str) == 0;
};
}
This function is from this helpful walkthrough article by Nic Raboy (https://blog.nraboy.com/2014/07/using-oauth-2-0-service-ionicframework/). I think that the problem may be in how I am presenting the data array, so if anyone has any experience in successfully implementing a Venmo API in Ionic, your help would be much appreciated!
I was actually able to solve this issue with the method described above. In my original code, I omitted the line used to set the content type to URL encoded (which was included in Nic's example). Once I added this line, the request functioned as expected. The line was as follows:
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

Twitter 4j - Get tweets by user ID - Processing

There seems to be many different tutorials and examples out there to allow for tweets to be pulled into Processing from one specific user.
And yet I'm still having problems getting any code to work. I have managed to get tweets by searching with hashtags, so the twitter4j library (latest) is working within Processing (also latest software). I still a complete coding novice...
I've found the following code to do exactly what I need, but unfortunately it isn't complete, where I'm assuming you need to declare your Consumer Keys and Access tokens... But I've no idea how to do this with this code. Is this something that someone is able to provide and explain?
Essentially, I need the full sketch... Any help would be greatly appreciated!
Code from elsewhere:
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
AccessToken accessToken = new AccessToken(TWITTER_TOKEN,
TWITTER_TOKEN_SECRET);
twitter.setOAuthAccessToken(accessToken);
try {
Status status = twitter.showStatus(Long.parseLong(tweetID));
if (status == null) { //
// don't know if needed - T4J docs are very bad
} else {
System.out.println("#" + status.getUser().getScreenName()
+ " - " + status.getText());
}
} catch (TwitterException e) {
System.err.print("Failed to search tweets: " + e.getMessage());
// e.printStackTrace();
// DON'T KNOW IF THIS IS THROWN WHEN ID IS INVALID
}
EDIT: This is how I've added the consumer/access keys - is this right?
twitter.setOAuthConsumer("MyConsumerKey", "MyConsumerSecret");
AccessToken accessToken = new AccessToken("MyAccessToken", "MyAccessTokenSecret");
twitter.setOAuthAccessToken(accessToken);
EDIT2: This is what I have now to get the User's tweets. But produced the error: 'cannot convert from ResponseList to Status'
String user="USER ID";
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("MY CONSUMER KEY", "MY CONSUMER KEY SECRET");
AccessToken accessToken = new AccessToken("MY TWITTER TOKEN", "MY TWITTER TOKEN SECRET");
twitter.setOAuthAccessToken(accessToken);
try {
Status status = twitter.getUserTimeline(user);
if (status == null) { //
// don't know if needed - T4J docs are very bad
} else {
System.out.println("#" + status.getUser().getScreenName()
+ " - " + status.getText());
}
} catch (TwitterException e) {
System.err.print("Failed to search tweets: " + e.getMessage());
// e.printStackTrace();
// DON'T KNOW IF THIS IS THROWN WHEN ID IS INVALID
}
you need first to create a twitter app, to do so go to https://apps.twitter.com/, from there you can get all the infos needed to get your credentials.
in your code just replace the 'CONSUMER_KEY','CONSUMER_KEY_SECRET','Access Token','Access Token Secret' by the credentials.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("XXXXX")
.setOAuthConsumerSecret("XXXXXX")
.setOAuthAccessToken("XXXX-XXXXX")
.setOAuthAccessTokenSecret("XXXXXXX");
hope this help!

Using Oltu to connect to Doorkeeper

I'm attempting to authenticate against a rails app running as an OAuth2 provider running Doorkeeper.
I'm attempting to modify an example from the Oltu sources. The code that I have currently is:
public class OAuthClientTest {
public static void main(String[] args) throws OAuthSystemException, IOException {
String authUri = "http://smoke-track.herokuapp.com/oauth/authorize";
String callback = "http://localhost:8080";
String clientId = "728ad798943fff1afd90e79765e9534ef52a5b166cfd25f055d1c8ff6f3ae7fd";
String secret = "3728e0449052b616e2465c04d3cbd792f2d37e70ca64075708bfe8b53c28d529";
String tokenUri = "http://smoke-track.herokuapp.com/oauth/token";
try {
OAuthClientRequest request = OAuthClientRequest
.authorizationLocation(authUri)
.setClientId(clientId)
.setRedirectURI(callback)
.setResponseType("code")
.buildQueryMessage();
System.out.println("Visit: " + request.getLocationUri() + "\nand grant permission");
System.out.print("Now enter the OAuth code you have received in redirect uri ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();
request = OAuthClientRequest
.tokenLocation(tokenUri)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(clientId)
.setClientSecret(secret)
.setRedirectURI(callback)
.setCode(code)
.buildBodyMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
//Facebook is not fully compatible with OAuth 2.0 draft 10, access token response is
//application/x-www-form-urlencoded, not json encoded so we use dedicated response class for that
//Own response class is an easy way to deal with oauth providers that introduce modifications to
//OAuth specification
GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, GitHubTokenResponse.class);
System.out.println(
"Access Token: " + oAuthResponse.getAccessToken() + ", Expires in: " + oAuthResponse
.getExpiresIn());
} catch (OAuthProblemException e) {
System.out.println("OAuth error: " + e.getError());
System.out.println("OAuth error description: " + e.getDescription());
}
}
}
When I run this example with the original Facebook credentials, it takes me to a page that allows authentication. When I use my rails app, I get a url of the form:
http://smoke-track.herokuapp.com/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080&client_id=728ad798943fff1afd90e79765e9534ef52a5b166cfd25f055d1c8ff6f3ae7fd
When I enter this in the browser I am forwarded to the redirect uri followed by:
?code=6d09201b18178ee7737fcdd330563143ef0b60855e9d06621dcec627a9c3f29a
When I enter the code at the prompt, I get the following errors:
OAuth error: invalid_request
OAuth error description: Missing parameters: access_token
I don't get that error when authenticating against Facebook. Any ideas as to what I am doing wrong?
you might try to use OAuthJSONAccessTokenResponse rather than GitHubTokenResponse

Retrieving oauth_token and oauth_token_secret (RestSharp on Windows Phone)

New to OAuth and RestSharp.
I'm building a Windows Phone app, using RestSharp to handle all the OAuth stuff.
private void LoginButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
RestClient client = new RestClient(OAuth.Auth.baseurl);
client.Authenticator = RestSharp.Authenticators.OAuth1Authenticator.ForRequestToken(OAuth.Auth.consumerkey, OAuth.Auth.consumersecret);
var request = new RestRequest("oauth/request_token", Method.POST);
client.ExecuteAsync(request, (response) =>
{
var resource = response.Content;
MessageBox.Show(resource);
webBrowser1.Navigate(new Uri(OAuth.Auth.UAuthorise + "?" + resource + "&oauth_callback=http://bing.com"));
});
}
private void webBrowser1_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show(e.Uri.ToString() + " loaded");
}
I'm successfully getting the request token, and then a user is able to log in to the service. webBrowser1 then navigates to bing.com (as defined in the callback url). My question is: what do I do to get the oauth_token and oauth_token_secret? I can see them, due to the webBrowser1_LoadCompleted event handler, but how can I extract them to use them in my program?
Handle the Navigating event for the browser control when it redirect back to the callback domain/Uri.
You can then extract the values you're after from from the Uri.

Resources