CodeTalker is a Spring Boot application designed to interface with GitHub repositories, allowing users to fetch dependency information from pom.xml
files within specified repositories using GitHub's OAuth for secure access.
Before running the application, ensure you have the following installed:
- Java JDK 11 or later
- Maven
- Postman for API testing
- Clone the repository from GitHub.
- Navigate to the application directory where the
pom.xml
is located. - Run the following command to start the application:
mvn spring-boot:run
The application should now be running on http://localhost:8080
.
- Open Postman.
- Create a new GET request to
http://localhost:8080/api/dependencies
. - Add query parameters:
repoName
: The name of the GitHub repository.owner
: The GitHub username or organization that owns the repository.
To access the GitHub API, the application uses OAuth for authentication. Here's how the flow works:
-
Request a User's GitHub Identity:
- Send a GET request to
https://github.com/login/oauth/authorize
with the required parameters, includingclient_id
and optionalredirect_uri
,login
,scope
,state
, andallow_signup
.
- Send a GET request to
-
Users Are Redirected Back to Your Site by GitHub:
- If the user accepts the request, GitHub redirects back to your site with a temporary code and the provided state.
- Exchange this code for an access token by sending a POST request to
https://github.com/login/oauth/access_token
withclient_id
,client_secret
,code
, and optionalredirect_uri
.
-
Use the Access Token to Access the API:
- The access token allows you to make requests to the API on behalf of a user.
- Set the Authorization header as
Bearer OAUTH-TOKEN
in your API requests.
In Postman, you can simulate the OAuth flow:
-
Get the Authorization Code:
- Manually navigate to the authorization URL in your web browser or set up an OAuth 2.0 authorization request in Postman with the Auth URL and the necessary parameters.
-
Get the Access Token:
- Use the "
Code" obtained in the previous step to make a POST request in Postman to the token URL with the required parameters (client ID, client secret, and code).
- Call the API Using the Access Token:
- Set up your GET request in Postman to the endpoint.
- Under the "Authorization" tab, select "Bearer Token" and paste your access token.
- Send the request to interact with the GitHub API.
-
Set up a GET request to
http://localhost:8080/api/dependencies
with the following query parameters:- Key:
repoName
, Value:[your-repo-name]
- Key:
owner
, Value:[repo-owner]
- Key:
-
In the "Headers" section, add the following:
- Key:
Authorization
, Value:Bearer [your-github-access-token]
- Key:
-
Send the request.
- Ensure the Spring Boot application is running and accessible.
- Confirm that you have correctly set up your GitHub OAuth application and that the
client_id
andredirect_uri
match what is registered on GitHub. - If you encounter any issues with the OAuth flow, review the GitHub documentation and ensure that the application's callback URL is correctly configured to handle the OAuth2 callback from GitHub.