Using OAuth

From DreamFactory
Jump to: navigation, search
(Created page with "Father's Day is a special time to celebrate and honor our dads, who do so much. Here are nine tips for helping your kids give a Father's Day gift he will remember for years to...")
 
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Father's Day is a special time to celebrate and honor our dads, who do so much. Here are nine tips for helping your kids give a Father's Day gift he will remember for years to come.<br><br>Ask the sales staff, and you want to read the ticket very carefully, in the event the ticket was received. There are numerous [https://banyetes.paeria.cat/?option=com_k2&view=itemlist&task=user&id=202464 snapfish coupon codes], but if you want to save money on a shop option is to recycle ink cartridges. Office Depot and Staples will recycle empty cartridges discount codes for $ 3. These cartridges are reconditioned by them and sell them as brand name shops.<br><br><br><br>Photograph cards at snapfish cost 29 cents each of photo paper that doesn't fold piece and are a single. It's your customized picture on a holiday ornamentation and one end on the next with your special message. There is a border across the picture. They've many holidays and occasions to select from, including Christmas, Winter Holidays and more.<br><br>Including a personal touch would be fantastic, in regards to select amazing gifts for him. So, photo gifts are sometimes a nice idea. It's possible for you to include his favourite image on coffee cups, photo books, luggage labels, mouse pads. These gifts CAn't only be enjoyable but also shows how much you care for him.<br><br>Other creative gift ideas for guys comprise in-home draft beer system (under $300!), personalized martini shakers and shot glasses, and gourmet-thing-of-the-month clubs. You can't go wrong with any of these amazing birthday gift suggestions.<br><br>Amazon Promo Code Codes has Tom's of Maine Antiplaque and Whitening Fluoride-free Toothpaste, Peppermint, 5.5-Oz (Pack of 2) for $6.04 with Subscribe and Save. Shipping is free. You may cancel Subscribe and Save any moment after your order ships.
+
=== Tutorial ===
 +
 
 +
To use OAuth in a DreamFactory instance, you need to provision an OAuth service in your instance. You can provision an
 +
OAuth service from the 'Services' tab in Admin Console. Click on the 'Create' button on the services tab to create a new
 +
service. Select an OAuth service provider (Facebook OAuth in this case) under the OAuth services from the 'Service Type'
 +
drop down menu. For the name field use a short, meaningful, one word name for your service. This will be used as your
 +
OAuth service identifier. Fill out rest of the information on this form and then go to 'Config' tab.
 +
 
 +
[[File:Oauth tutorial 1.png|800px]]
 +
 
 +
On the config form you will need to provide all the details of your OAuth provider and select a default role for your
 +
OAuth service. This role will be assigned (for all applications in the system) to all users signing in using this OAuth service.
 +
 
 +
You will also need to provide a Redirect URL here. Your Redirect URL should be the URL of your app that the OAuth service
 +
provider (Facebook in this case) can use to reach back to your app with the Authorization Code. One important thing about
 +
the redirect URL is that you will need to include your service name in it. In this example, the service name is
 +
part of URL query string (?service=facebook). This is important because it's the only identifier of your service in your
 +
DreamFactory instance. This is how your app will know which service to use for handling the callback when Facebook calls back
 +
to your application using this redirect URL.
 +
 
 +
Once the service is successfully provisioned it is ready for authenticating your users.
 +
 
 +
[[File:OauthTutorial2.png|800px]]
 +
 
 +
 
 +
=== API Endpoints ===
 +
 
 +
==== Redirecting to OAuth provider's site for signing in. ====
 +
 
 +
 
 +
<pre>POST https://your-url/api/v2/user/session?service={oauth_service_name}</pre>
 +
 
 +
-- OR --
 +
 
 +
<pre>POST https://your-url/api/v2/user/session</pre>
 +
 
 +
<source lang=JavaScript>
 +
{
 +
    "service" : "oauth_service_name"
 +
}
 +
</source>
 +
 
 +
==== Signing into your DreamFactory Instance ====
 +
 
 +
<pre>POST https://your-url/api/v2/user/session?oauth_callback=true&{query_string_from_callback_containing_authorization_code_and_service_name}</pre>
 +
 
 +
=== Example - Sign-in using Facebook ===
 +
 
 +
* Service name: facebook
 +
* Request URL <pre>POST https://your-url/api/v2/user/session?service=facebook</pre>
 +
* Response:
 +
<source lang=JavaScript>
 +
{
 +
"response": {
 +
"redirect": true,
 +
"url": "https://www.facebook.com/v2.4/dialog/oauth?client_id=123&redirect_uri=foo&scope=email&response_type=code"
 +
}
 +
}
 +
</source>
 +
* Use the 'URL' in the response to redirect to Facebook's login page.
 +
* After successful login, Facebook redirects back to your app with the authorization code and service name as a URL query string.
 +
* Extract the entire URL query string from Facebook's callback URL and make the following request to sign into your DreamFactory instance.
 +
* Request URL <pre>POST https://your-url/api/v2/user/session?oauth_callback=true&{extracted_query_string_from_callback}</pre>
 +
* Response:
 +
<source lang="JavaScript">
 +
{
 +
    "session_token": “abc.123abc.efg”,
 +
    "session_id": “abc.123abc.efg”,
 +
    "id": 1,
 +
    "name": "John",
 +
    "first_name": "John",
 +
    "last_name": "Doe",
 +
    "email": "jdoe@gmail.com",
 +
    "is_sys_admin": false,
 +
    "last_login_date": "2015-06-30 16:46:59",
 +
    "host": "your-url"
 +
}
 +
</source>

Latest revision as of 14:37, 20 July 2016

Tutorial

To use OAuth in a DreamFactory instance, you need to provision an OAuth service in your instance. You can provision an OAuth service from the 'Services' tab in Admin Console. Click on the 'Create' button on the services tab to create a new service. Select an OAuth service provider (Facebook OAuth in this case) under the OAuth services from the 'Service Type' drop down menu. For the name field use a short, meaningful, one word name for your service. This will be used as your OAuth service identifier. Fill out rest of the information on this form and then go to 'Config' tab.

Oauth tutorial 1.png

On the config form you will need to provide all the details of your OAuth provider and select a default role for your OAuth service. This role will be assigned (for all applications in the system) to all users signing in using this OAuth service.

You will also need to provide a Redirect URL here. Your Redirect URL should be the URL of your app that the OAuth service provider (Facebook in this case) can use to reach back to your app with the Authorization Code. One important thing about the redirect URL is that you will need to include your service name in it. In this example, the service name is part of URL query string (?service=facebook). This is important because it's the only identifier of your service in your DreamFactory instance. This is how your app will know which service to use for handling the callback when Facebook calls back to your application using this redirect URL.

Once the service is successfully provisioned it is ready for authenticating your users.

OauthTutorial2.png


API Endpoints

Redirecting to OAuth provider's site for signing in.

POST https://your-url/api/v2/user/session?service={oauth_service_name}

-- OR --

POST https://your-url/api/v2/user/session
{
    "service" : "oauth_service_name"
}

Signing into your DreamFactory Instance

POST https://your-url/api/v2/user/session?oauth_callback=true&{query_string_from_callback_containing_authorization_code_and_service_name}

Example - Sign-in using Facebook

  • Service name: facebook
  • Request URL
    POST https://your-url/api/v2/user/session?service=facebook
  • Response:
{
	"response": {
		"redirect": true,
		"url": "https://www.facebook.com/v2.4/dialog/oauth?client_id=123&redirect_uri=foo&scope=email&response_type=code"
	}
}
  • Use the 'URL' in the response to redirect to Facebook's login page.
  • After successful login, Facebook redirects back to your app with the authorization code and service name as a URL query string.
  • Extract the entire URL query string from Facebook's callback URL and make the following request to sign into your DreamFactory instance.
  • Request URL
    POST https://your-url/api/v2/user/session?oauth_callback=true&{extracted_query_string_from_callback}
  • Response:
{
    "session_token": “abc.123abc.efg,
    "session_id": “abc.123abc.efg,
    "id": 1,
    "name": "John",
    "first_name": "John",
    "last_name": "Doe",
    "email": "jdoe@gmail.com",
    "is_sys_admin": false,
    "last_login_date": "2015-06-30 16:46:59",
    "host": "your-url"
}