-
Notifications
You must be signed in to change notification settings - Fork 71
[v4] Add IP Address to API Access Tokens #12141
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds IP address tracking to API access tokens to help users see where their OAuth tokens were created or refreshed, particularly useful for mobile app authentication. The implementation captures the IP address during token creation, stores it in the database, and displays it with geolocation information on the security page.
Key Changes:
- Added
ip_address(inet) column toapi_tokenstable with an index - Configured Doorkeeper to capture and store IP addresses during token operations
- Added geocoding methods to ApiToken model for displaying location on a map
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
db/migrate/20251117030308_add_ip_address_to_api_tokens.rb |
Migration adding ip_address column and index to api_tokens table |
db/schema.rb |
Schema update reflecting the new ip_address field and index |
config/initializers/doorkeeper.rb |
Configured custom token attributes and hook to capture IP address on successful authentication |
app/models/api_token.rb |
Added geocoding methods (geocode_result, latitude, longitude) to retrieve location from IP |
app/views/users/_oauth_authorization.erb |
Updated OAuth authorization view to display map and IP address for tokens |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Summary of the problem
Currently in security page we don't show where that token was created and in context of Mobile app we would like to see where we logged in (or where token was refreshed)
Describe your changes
I added an IP address field to the API Token model then doorkeeper will update the token object after a successful response with the remote IP. Added some model functions to get lat and long for security page map