问题
I want to use google cloud print service for my application, Concept is : Buyer can purchase products from my site and he should send order list to supplier's printer.
For this, Supplier should registor printer in their google account, buyer will send print request to selected supplier's printer, and order document should be printed on supplier's printer.
Problem is : Cloud print application is using OAuth2 autherization and it requries google account login and client_id to obtain access token. So for geting list of printers and submiting print job, buyer needs to login from google account with the supplier's google credentials from backend. (With or without browser) That's not acceptable as it will also allow buyer to use other google services (e.g. mail,docs) of supplier's account.
So my question is , Is there any other method to get access token? Any other solution is also welcome.
Note: I have taken reference from google-pythonCode and cloudprinting module.
回答1:
What you want to do is to have the suppliers authorize with OAuth2 and store their access_token and more importantly refresh_token. The buyers do not need to authorize with Google at all, you can simply send their print job to the suppliers printer with the appropriate suppliers access token. This also makes it easier to handle the access to the different printers as each suppliers Google account already has access to their own printer.
The refresh token is a long living token (valid until revoked by supplier) that allows you to get new access tokens even after the expiration of the short lived (1 hour) access token.
来源:https://stackoverflow.com/questions/14851544/access-token-for-google-cloud-print-service