Using OAuth

From DreamFactory
Jump to: navigation, search
m
(Created page with "### 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 A...")
Line 1: Line 1:
If you're a regular traveler, then you ought to know that finding airfares and cheap hotels entails no luck only patience and effort. There are those voyagers who get the things that they need and nevertheless be able to save a few dollars along the way - it's possible for you also as the secret to that are promotions like coupon code codes.<br><br>There may be plenty of methods about how you are able to find discounted golf clubs. One best place to search for is the local newspaper for [https://forums.cartownstreets.com/member.php?777406-LelandVale forums.cartownstreets.com]. However, this system possibly rather limited in your location considering that there might no sports stores seen in your place. Another excellent alternative is the ###contextlinks1 which can be get clubs ### and promotions for golf from the retailers. But now, in trying to find discount golf clubs that are great, the most famous method is through the search engines. You can locate a lot of equipment dealers and golf shops that provide discounted golf clubs by surfing online.<br><br>Normally, you look for a gift that'll please the receiver. Yet, going back to our earlier example, massage chairs are sold by an organization like Brookstone and those can cost from $100 - $250 just to get them to your house. The fulfillment that you will manage to get out of what you've accomplished for your loved one is immeasurable. Whether you purchased it using a snapfish coupon code or got it with the regular price, It's still the same. Dotphoto delivers 20 free photo prints for signing up, as well as their shipping charges are $3. You can think of something you made it by yourself.<br><br>photo books have become the go to item when somebody wants an actual book to reveal to buddies and family with out having to lug about their computers. photo books are simple to design and order. Most sites will have an easy application that anyone can utilize to upload their photos. Some will let you make a scrap book of sorts to add components that are artsy to generate your photo book that a lot a lot more private.<br><br>Potted plants are a great alternative as unusual Christmas gifts or as Valentine's Day presents. You can gift the potted plant, which acts as a sign of your love for the individual. With the growth of the plant, your love will even grow. The gift is certain to win hearts and eventually be a memorable one as well. However, there is a small problem to it. You mightn't be aware of plants and also the manner to look after it. There's an alternative to it as well. Get the potted plant from a nursery. People in the nursery will direct you to care for it correctly. Online help is available if that looks challenging. There are several on-line portals that deal with these.<br><br>It's always underestimated, and could even be seen as kitsch, but for people who love getting personal gifts from memorable moments, these are perfect and help you out when you're at your wits end and cannot select what to give someone.
+
### 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 use 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 with 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 case,I am including the service name as
 +
part of URL query string (?service=facebook). This is important because this is the only identifier of your service in your
 +
DreamFactory instance. This is how your app will know which service to use for handling callback when Facebook calls back
 +
your application using this redirect URL.
 +
 
 +
[[File:Oauth tutorial 2.png|800px]]
 +
 
 +
Once the service is successfully provisioned it is ready for authenticating your users.
 +
 
 +
### 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 response to redirect to Facebook's login page.
 +
* After successful login Facebook redirects back to your app with authorization code and service name on URL query string.
 +
* Extract the entire URL query string from Facebook's callback URL and make following request to signing 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>

Revision as of 20:24, 21 September 2015

      1. 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 use 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 with 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 case,I am including the service name as part of URL query string (?service=facebook). This is important because this is the only identifier of your service in your DreamFactory instance. This is how your app will know which service to use for handling callback when Facebook calls back your application using this redirect URL.

Oauth tutorial 2.png

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

      1. API Endpoints
        1. 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"
}
        1. 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}
      1. 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 response to redirect to Facebook's login page.
  • After successful login Facebook redirects back to your app with authorization code and service name on URL query string.
  • Extract the entire URL query string from Facebook's callback URL and make following request to signing 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"
}