replaysMike / Binner

Open source parts inventory system for makers, electronics hobby, and professional engineers
https://binner.io
GNU General Public License v3.0
261 stars 41 forks source link

[Bug]: Entering three letters in the Add Part opens the DigiKey authentication page automatically #257

Closed shankarkrupa closed 5 months ago

shankarkrupa commented 5 months ago

Binner version

v2.6.23

Operating System

Web version

Describe the bug and the steps to reproduce it

Steps to reproduce:

1) Go to Add Inventory page 2) Enter three letters, bat in an attempt to type battery 3) Before you type battery, you will see a new tab opened and the cursor focus is on the new tab

Additional Notes: With the keyup events, a call is made to the DigiKey API parts search to the endpoint https://binner.io/api/part/info?partNumber=bat&supplierPartNumbers=digikey:,mouser:,arrow: . I guess the error "User must authorize" response causes a redirect to the authorization page forcing a sign in.

Would you like to attach your appsetings.json configuration?

N/A, happens in the cloud version

Screenshots or Videos (Optional, but they help!)

No response

Are you able to contribute a PR? (No is ok!)

Maybe, I'll investigate and start debugging

shankarkrupa commented 5 months ago

Thought of checking if this is something to be fixed or is a by design thing needing a digikey account to use binner.io.

shankarkrupa commented 5 months ago

I guess this is because of https://github.com/replaysMike/Binner/blob/65b35db799f1708a341fbcd6f6fc16b8edda0a55/Binner/Binner.Web/ClientApp/src/pages/Inventory.js#L384

includeInventorySearch ()
if (data.requiresAuthentication) {
        // redirect for authentication
        window.open(data.redirectUrl, "_blank");
        return { data: null, existsInInventory: false };
      }

Can this be driven through a setting either in the UI or a global setting instead of being driven directly by the data.requiresAuthentication flag?

replaysMike commented 5 months ago

Hi there @shankarkrupa - this is intended behavior if DigiKey is enabled in settings. It's due to the way DigiKey's api works, they use oAuth and only provide their UI to authenticate. Once you've done that once it will be remembered for a fair chunk of time.

Alternatively if you don't use DigiKey, you can disable it in the Settings page.

shankarkrupa commented 5 months ago

Hi @replaysMike I get it now. The bug can be closed.

In the binner.io hosted version, I could not find an option to control the DigiKey lookup. Could it be because my role is not an admin on the site as I signed up? I only see an Account Settings link under the Profile icon.

replaysMike commented 5 months ago

It's located under the Settings section on the home page. However, I just found a bug in saving those settings that was introduced last night. There is a fix for this deploying right now, it will be live in about 20 minutes.

image

image

replaysMike commented 5 months ago

it also gave me a thought that I should introduce a new feature explaining why the popup happens. This already happens on the Settings page when you choose "Test API", I'll add this to the Inventory page as well.

replaysMike commented 5 months ago

ok I've added the new prompt on all the other pages as well, will be released live in 20 min. Thanks for triggering this suggestion :)