0

I am trying to develop a POC using UserGrid where a user can signup and then login and then can simply upload images to store online and download it later. Somewhat similar to a OneDrive.

I am using the api.usergrid.com

Using the dashboard I have created some Roles(admin, default, guest, etc) and assigned them Permissions.

So whenever I signup a new user how can assign that user a role using php?

I am using this as a reference: https://github.com/apache/usergrid/tree/master/sdks/php

amitection
  • 2,696
  • 8
  • 25
  • 46

1 Answers1

0

There doesn't appear to be a specific SDK method for this right now. But when you create the user, you can use post the connection directly with $client->post($endpoint, $query_string_array, $body) where the endpoint is roles//users/

Request is described here: http://usergrid.apache.org/docs/security-and-auth/using-roles.html

There's a connection method in the SDK, but it requires a connection type, which is a different syntax for this type of role connection.

amuramoto
  • 2,838
  • 1
  • 11
  • 15
  • Thanks for the reply. But I don't get it still. Could you please illustrate with an example? – amitection Mar 03 '16 at 09:09
  • `$body = array('name'=>'guest'); $query_string_array = array(); $endpoint = "roles/guest/users/".$_POST['username']; $client-post($endpoint,$query_string_array,$body);` I have tried this, But still gives an 'Unauthorized exception error' – amitection Mar 03 '16 at 10:08
  • You probably need to add your app level client_id and secret to the request, since a regular user can't assign permissions/roles. The Client has a set_client_id and set_client_secret methods if you want the credentials to be sent with every request (this might be ok since you're doing this server side), or you can probably change your endpoint to be: $endpoint="roles/guest/users/?client_id=yourclientid&secret=yoursecret" – amuramoto Mar 04 '16 at 17:42
  • Thanks a lot! It worked. I was missing the client `set_client_id` and `set_client_secret ` methods. – amitection Mar 05 '16 at 11:31