Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug OAuth1 authentication problem (Twitter v2 API) in Java with scribejava #1668

Closed
mikebgrep opened this issue Jan 8, 2023 · 0 comments

Comments

@mikebgrep
Copy link

mikebgrep commented Jan 8, 2023

I am trying to make a request to Tweeter with OAuth1 authentication method in Python I manage to do it with requests library but on Java I use Rest assured. Following code does not work, its return Unauthorized. I check online the solution appear to add scribejava dependency so auth().oauth() to work without extra work :

Envirument: Java 8

 public static Headers headerEmpty() {
        Header contentType = new Header("Content-Type", "application/json");
        Header acceptType = new Header("Accept", "*/*");

        List<Header> headerList = new ArrayList<>();
        headerList.add(contentType);
        headerList.add(acceptType);

        return new Headers(headerList);
    }
 Response response = given()
            .headers(headerEmpty())
            .auth()
            .oauth(twitterSettings.getApiKey(), twitterSettings.getApiKeySecret(),
                    twitterSettings.getAccessToken(), twitterSettings.getAccessTokenSecret())
            .spec(baseUrl)
            .get("users/me")
            .then()
            .extract().response();
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>5.3.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.groovy</groupId>
                    <artifactId>groovy-xml</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>xml-path</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.scribejava</groupId>
            <artifactId>scribejava-core</artifactId>
            <version>8.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.scribejava</groupId>
            <artifactId>scribejava-apis</artifactId>
            <version>8.3.3</version>
        </dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant