Open JoeCohen opened 2 weeks ago
Pulk's Mirror. https://github.com/JacobPulk/mirror
rough outline:
- you redirect your user to iNat,
- the user is offered the choice to authorize your app with access to their iNat data, and
- If they agree, they are redirected to the redirect_uri you specified with an access_token in the params.
https://www.inaturalist.org/pages/api+reference#authorization_code_flow
Questions:
Rails.application.credentials.secret_key_base
iNatImport
request?require rest_client
see https://www.inaturalist.org/pages/api+reference#authorization_code_flowCreated iNat application https://www.inaturalist.org/oauth/applications/851
params in the callback action If iNat user approves the request:
(rdbg) params
#<ActionController::Parameters {"code"=>"NtX2QvCzQuwXAyKL0uDtvZLcWDLQpo4i5QWkAtTMT1g", "controller"=>"observations/inat_imports", "action"=>"auth"} permitted: false>
If iNat user denies the request:
(rdbg) params
#<ActionController::Parameters {"error"=>"access_denied", "error_description"=>"The resource owner or authorization server denied the request.", "controller"=>"observations/inat_imports", "action"=>"auth"} permitted: false>
How to proceed after receiving code
from iNat at the callback url?
@nwilson-eol's suggestion:
InatImport#create
create an InatImport
model object with a status
attribute
status
would be things like requesting_authorization
request_token
, etc.redirect url
, User.current should be the same. So we can figure out which MO user it is (and other stuff, e.g., iNat Observation ids that are stored with the InatImport object for that user.InatImport
object20240719 0720 Pacific Not working as expected as of #29809c667b67d86d13445496aa4d59333f8f2a2
Update API request to === iNat docs
- fixes headers
- uses RestClient instead of Httparty
See https://www.inaturalist.org/pages/api+reference#authorization_code_flow
The response does not include private location.
Probably because authentication isn't working. But there's a slim chance that iNat doesn't include private location even if the request is authenticated.
But I tried setting a breakpoint in inat_search_observations
right after ::Inat.new ...
then manually
RestClient.get("#{API_BASE}/users/me", headers)
RestClient::Unauthorized: 401 Unauthorized
from /Users/joe/mushroom-observer/app/classes/inat.rb:15:in `initialize'
I don't understand this. But I've been stuck on this a while. So I'll put it aside for the moment, and work on things that depend on authentication.
Link to an old iNat app that imported MO Observations: https://www.inaturalist.org/posts/20053-18-mushroom-observer-api-key
Authenticate iNat imports with iNat API Key and user handshake. For details and documentation see https://github.com/MushroomObserver/mushroom-observer/issues/1955#issuecomment-2016029239
Tasks
new
button name =>Submit
orContinue
iNatImport
modelhttparty https://api.stackexchange.com/2.2/questions?site=stackoverflow