33

I'm sure related questions have been asked, but I cannot find this answer. I'm trying to make a simple ruby api wrapper for Office 365, and I can't figure out how to get an oauth app created (secret/token/callback url/.

In everyone else's oauth/api universe you head to a developer portal and create an 'Application' which comes with a token and secret to use with your generic oauth library to do the 3 legged browser based authentication. I am not going to touch any windows/.net software to accomplish this - we are in ruby land.

I think based on the documentation I need to head to the windows azure management portal to create something, but I can't figure out exactly what - and the things I did create are not giving me token/secret/urls - shouldn't it ask for the callback url/domain?

For the oauth gem, I'm looking for these types of details;

def connection(credentials)
  OAuth2::Client.new(
      credentials[:client_id],
      credentials[:client_secret],
      :site => credentials[:base_url],
      :authorize_url => '/api/v1/oauth2/authorize',
      :token_url => '/api/v1/oauth2/token'
  )
end
Troy Anderson
  • 616
  • 1
  • 6
  • 10
  • 8
    It's weird how difficult it is to find this information. Almost as though Microsoft forgets that most developers aren't using .NET for everything. – Andrew Thaddeus Martin Jun 24 '15 at 13:01
  • I also found this quite useful : http://paulryan.com.au/2014/spo-remote-authentication-rest/ – potame Jun 01 '17 at 08:48
  • this one is up-to-date and works fine: https://docs.printandshare.info/hands-on/email/send-emails-via-office365-azure – juFo Dec 12 '18 at 09:27

1 Answers1

41

[Update Aug 20th, 2015]: It looks like there is a new getting started experience, which will help register your app, and even create a starter project in the language of your choice. I would certainly recommend trying that first, rather than going through the manual steps outlined below.


To register apps manually (e.g., not through Visual Studio and Office 365 API Tools), you will need to go to the Azure Management portal at https://manage.windowsazure.com/. Depending on the SKU of your Office 365 tenant, You may be able to sign in with your O365 account. If not, there's a manual step you can do to associate an Azure portal (e.g., one accessed via a Live ID) with your O365 tenant. Let me know if you need this information.

Assuming you are able to get into the Active portal, find the Active Directory node there, and choose the directory that corresponds to your O365 tenant.

From there, select "Applications" and "Add Existing" to register your app: Select "Applications" and "Add Existing" to register your app:

Choose "Add an application my organization is developing" Choose "Add an application my organization is developing"

And fill out the details: Fill out the details (Step 1) Fill out the details (Step 2)

Once the application is created, go to the configure tab. There you will find the client ID, you can generate the secret, and (maybe most importantly) set permissions for your app to access the Office 365 APIs.

Configure Tab with client ID, permissions, etc

Hope this helps!

UPDATE:

After registering the app, I would highly encourage you to look at the samples found here: Web app and Native (in this case, Windows 8.1) app. These have great examples of how to do OAuth, and you can also see what endpoints are used to access the different services (and an example of Service Discovery for SharePoint, for example).

Within the samples, the API endpoint & Resource ID information for services can be found under the "Office365ServiceInfo.cs" file (under "Models" folder in web app and "Office365" folder for native app), and the auth code can be found under "Controllers/Office365CommonController" for the web app and "Office365/Office365Helper" for the native app. I would also encourage you to read the "Exploring the Project Structure" section of this blog post.

UPDATE 2: MSDN documentation that describes adding and configuring applications in the Azure portal can be found here: http://msdn.microsoft.com/en-us/library/dn132599.aspx

UPDATE 3: New documentation has been added to MSDN, which covers both the steps above, and also how to get access to the Azure Portal for your O365 Dev Site: http://msdn.microsoft.com/en-us/library/office/dn736059(v=office.15).aspx

~Michael

Allart
  • 830
  • 11
  • 33
  • Wow - this got me a lot further than I had been :) What would the actual full endpoint be for these urls? ```` :authorize_url => '/api/v1/oauth2/authorize', :token_url => '/api/v1/oauth2/token' ```` – Troy Anderson Mar 28 '14 at 02:08
  • Troy, the OAuth URL is generally of the form https://login.windows.net/{tenant}/oauth2/authorize?response_type=code&client_id={client_id}&resource={resource_you_want_to_access}&redirect_uri={redirect}. You would also add a state parameter, to prevent Cross-Site Request Forgery attacks. The tenant can either be hard-coded to a particular tenant, or you can use the special word "common" if you want it to work against any tenant. – Michael Zlatkovsky - Microsoft Mar 28 '14 at 20:51
  • Troy, also see my update to the question above, with links to sample code where you can find the OAuth URL and more. – Michael Zlatkovsky - Microsoft Mar 28 '14 at 21:00
  • Thanks everyone - we have an initial version of our Ruby wrapper going, we are going to see if we can create some calendar entries and report back. The API doc was a little fuzzy about how to make appointments vs meetings with attendee invites, but here it is; https://gist.github.com/theinventor/9954855 – Troy Anderson Apr 03 '14 at 13:59
  • @MichaelZlatkovsky-Microsoft Most of your links do not work anymore :(. I dont know where they all should go exactly. But if anyone can make an edit and fix them, would be nice :D – Allart Aug 06 '21 at 06:54
  • @Allart, I have long since moved on to a different team -- but I will forward this to someone who might know where http://dev.office.com/getting-started/office365apis should point to nowadays, and can update the top of this answer if I get a reply – Michael Zlatkovsky - Microsoft Aug 07 '21 at 13:52