I used the following request from the Graph api documentation to generate an access token to make calls for the Onedrive API. It works but the access token can only be accessed by the redirect URL from the request which only shows up on browser. How can I access the token via code and if I can't, than how can I generate a long lasting access token.
The aim is to make a server the received files and passes them to Onedrive, but I don't want it to request permision form a user everytime or to open a browser page to get the access everytime. I just need an automated access token that will let me access my orgnization's one drive.
You can register an app in your organization and grant it app-level permissions, then you don't need any user. Here is a step-by-step tutorial from Microsoft: https://learn.microsoft.com/en-us/graph/auth-v2-service
Note: to do that, you'll need your organization's admin consent. Also most authentication libraries like MSAL support this scenario out of the box, you don't really need to make GET/POST requests manually.