Skip to content

[New Feature]Add grpc.default_authority option for authorization #35

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

Closed
jcai opened this issue Oct 6, 2020 · 6 comments
Closed

[New Feature]Add grpc.default_authority option for authorization #35

jcai opened this issue Oct 6, 2020 · 6 comments

Comments

@jcai
Copy link

jcai commented Oct 6, 2020

I want to use grpc.default_authority to identify the current user.Could we add grpc.default_authority option to gRPC channel?

see:
wechaty/puppet-service#78
wechaty/go-wechaty#69
wechaty/java-wechaty#77

@jcai
Copy link
Author

jcai commented Oct 6, 2020

options = (('grpc.default_authority', token),)

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Oct 28, 2020

In python grpclib tools, you need to feed auth_token to the metadata. refer to : grpclib client auth.

Can you read from the metadata ?

@jcai
Copy link
Author

jcai commented Oct 28, 2020

Use channel option,not metadata

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Nov 1, 2020

@jcai Yes, adding option to channel is easy, but there are some incompatibility problems between betterprotogrpclib and grpcio.

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Nov 1, 2020

Find a trick solution:

import asyncio

from chatie_grpc.wechaty import PuppetStub
from grpclib.client import Channel


async def main():
    target = "server-address:port"
    channel = Channel(host="server-address", port=port)
    # this is the private field 
    channel._authority = "your-token"
    sub = PuppetStub(channel)
    await sub.start()
    print("started ...")
    async for response in sub.event():
        print(response)

asyncio.run(main())

output:

started ...
EventResponse(type=22, payload='{"qrcode":"http://weixin.qq.com/x/I7He3Ou3_pzXqJFzAQ5M","status":2}')
EventResponse(type=22, payload='{"data":"{\\"status\\":\\"Waiting\\"}","status":2}')
EventResponse(type=22, payload='{"data":"{\\"status\\":\\"Waiting\\"}","status":2}')

this works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants