posty / posty_chef

Chef Cookbook for a full Posty Mailserver Installation
www.posty-soft.org
Other
22 stars 8 forks source link

{"error":"Unauthorized. Invalid or expired token."}' when using posty-client #13

Closed ngphban closed 8 years ago

ngphban commented 8 years ago

Hi, I've successfully boot-strapped my node with posty-chef cookbook. However when I started using posty-client to add my first domain, I got the same error:

root@ip-172-31-19-216:/srv/posty_api# posty-client domain add example.org
PostyClient::Resources::Domain :: load failed with (401) '{"error":"Unauthorized. Invalid or expired token."}'
create PostyClient::Resources::Domain : example.org
"Unauthorized. Invalid or expired token."

My client config is below:

root@ip-172-31-19-216:/srv/posty_api# cat ~/.posty_client.yml 
development:
  api_url: https://ip-172-31-19-216.ap-southeast-1.compute.internal/posty_api/api/v1
  api_version: v1
  access_token: 5d470051c51180bc1eca07511be64487

This config is created upon bootstrapping as you can see below:

   * template[/root/.posty_client.yml] action create
     - create new file /root/.posty_client.yml
     - update content in file /root/.posty_client.yml from none to 7aa7da
     --- /root/.posty_client.yml    2016-03-11 06:19:31.498050999 +0000
     +++ /root/.chef-.posty_client.yml20160311-1430-1pxbvx8 2016-03-11 06:19:31.498050999 +0000
     @@ -1 +1,5 @@
     +development:
     +  api_url: https://ip-172-31-19-216.ap-southeast-1.compute.internal/posty_api/api/v1
     +  api_version: v1
     +  access_token: 5d470051c51180bc1eca07511be64487
     - change mode from '' to '0644'
     - change owner from '' to 'root'
     - change group from '' to 'root'

I have no idea why this token is invalid... I'd like to have some additional questions:

  1. Are those tokens generated randomly so they're different on each deployment?
  2. What does 'development' in above template really mean? Is it related to default "rack_env" value in attribute file? I tried to change this attribute to 'production' but seems the posty-client config is still the same.

Thank you for your great cookbook!

chicobico commented 8 years ago

Please try rake api_key:generate and write the new generated api_key to your config file.

  1. it should generate a api_key only once
  2. posty_client can be used with multiple environments e.g. mailserver1, mailserver2 the development namespace is the default one If you want to use the namespace mailserver1 then you must set ENV['POSTY_ENV'] to mailserver1