Skip to content

Pub/Sub: What is 'your-token' in the Pub/Sub GAE sample #2620

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
ahmetsan opened this issue Dec 16, 2019 · 4 comments
Closed

Pub/Sub: What is 'your-token' in the Pub/Sub GAE sample #2620

ahmetsan opened this issue Dec 16, 2019 · 4 comments
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. type: question Request for information or clarification. Not an issue.

Comments

@ahmetsan
Copy link

##2437

[your-app-id].appspot.com/_ah/push-handlers/receive_messages?token=[your-token]

your-app-id is my project id. but where can i find "your-token"

@busunkim96 busunkim96 assigned anguillanneuf and unassigned dmahugh Dec 16, 2019
@busunkim96 busunkim96 added type: question Request for information or clarification. Not an issue. api: pubsub Issues related to the Pub/Sub API. labels Dec 16, 2019
@busunkim96 busunkim96 changed the title Token Pub/Sub: What is 'your-token' in the Pub/Sub GAE sample Dec 16, 2019
@radianceltd
Copy link

I ran into the following problems when adding a gateway on the client side

cryptography==2.7
flaky==3.6.1
gcp-devrel-py-tools==0.0.15
google-api-python-client==1.7.11
google-auth-httplib2==0.0.3
google-auth==1.6.3
google-cloud-iot==0.3.0
google-cloud-pubsub==1.0.0
oauth2client==4.1.3
paho-mqtt==1.4.0
pyjwt==1.7.1
@classmethod
    def create_gateway(cls, service_account_json, project_id, cloud_region, registry_id, device_id,
            gateway_id, certificate_file, algorithm):
        """Create a gateway to bind devices to."""
        # [START iot_create_gateway]
        # Check that the gateway doesn't already exist

        exists = False

        os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = current_app.config['GOOGLE_APPLICATION_CREDENTIALS']

        # credentials = service_account.Credentials.from_service_account_file(
        # "your-json-file - path -with-filename.json")

        client = iot_v1.DeviceManagerClient()

        parent = client.registry_path(project_id, cloud_region, registry_id)
        devices = list(client.list_devices(parent=parent))

        for device in devices:
            if device.id == gateway_id:
                exists = True
            print('Device: {} : {} : {} : {}'.format(
                device.id,
                device.num_id,
                device.config,
                device.gateway_config
            ))

        with io.open(certificate_file) as f:
            certificate = f.read()

        if algorithm == 'ES256':
            certificate_format = 'ES256_PEM'
        else:
            certificate_format = 'RSA_X509_PEM'

        # TODO: Auth type
        device_template = {
            'id': gateway_id,
            'credentials': [{
                'public_key': {
                    'format': certificate_format,
                    'key': certificate
                }
            }],
            'gateway_config': {
                'gateway_type': 'GATEWAY',
                'gateway_auth_method': 'ASSOCIATION_ONLY'
            }
        }

        if not exists:
            res = client.create_device(parent, device_template)
            print('Created Gateway {}'.format(res))
            return True
        else:
            print('Gateway exists, skipping')
            return False
        # [END iot_create_gateway]

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses"
	debug_error_string = "{"created":"@1576569855.416981000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3934,"referenced_errors":[{"created":"@1576569855.416980000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":393,"grpc_status":14}]}"
>

@busunkim96
Copy link
Contributor

@radianceltd It looks like you're running into a different problem. Would you mind opening a new issue with the contents of your last post? It'll make it easier for us to track both issues. Thank you!

@anguillanneuf
Copy link
Member

Hi @ahmetsan, thanks for your question!

[your-app-id].appspot.com/_ah/push-handlers/receive_messages?token=[your-token] is the push endpoint when you set up your push subscription. [your-token] is an alphanumeric string that you can specify. If you for instance choose 1234abc, you can save it in app.yaml:

# This token is used to verify that requests originate from your
# application. It can be any sufficiently random string.
PUBSUB_VERIFICATION_TOKEN: 1234abc

And use it like this:

if (request.args.get('token', '') !=
current_app.config['PUBSUB_VERIFICATION_TOKEN']):
return 'Invalid request', 400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

5 participants