{"_id":"54738fbd007eb108007e041f","category":{"_id":"546b90a0b47b5d1400109ee2","project":"545137a814af501a00b50cf9","pages":["54738f761a20c70800e189bc","54738f7f1a20c70800e189be","54738f91007eb108007e041d","54738fa71a20c70800e189c1","54738fbd007eb108007e041f","54739056007eb108007e0421"],"version":"545137a814af501a00b50cfc","__v":6,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-18T18:32:00.749Z","from_sync":false,"order":6,"slug":"sdks","title":"SDKs"},"version":{"_id":"545137a814af501a00b50cfc","project":"545137a814af501a00b50cf9","__v":11,"createdAt":"2014-10-29T18:53:28.525Z","releaseDate":"2014-10-29T18:53:28.525Z","categories":["545137a814af501a00b50cfd","545138eaa66f020800dbab4a","546b9072b47b5d1400109edf","546b9082b47b5d1400109ee0","546b9088b47b5d1400109ee1","546b909462515a14007ebc43","546b90a0b47b5d1400109ee2","546ced235884600e007a92f6","5481008eea7fd40b00cd7c2b","573b9d83ee2b3b220042291f","57be1efa15efc70e006a5f99"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"githubsync":"","project":"545137a814af501a00b50cf9","user":"5433099f9a2b451a00ad4531","__v":4,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-11-24T20:06:21.218Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"try":true,"basic_auth":false,"auth":"never","params":[],"url":""},"isReference":false,"order":5,"body":"The Windows Phone 8 SDK provides you with the code necessary to integrate Yammer functionality into Windows Phone apps. It enables the following:\n\n1. Allows users to do an OAuth 2 login to the Yammer network using the IE browser\n\n2. Obtains an authToken and stores it securely to the Isolated Storage\n\n3. Uses that authToken to make all subsequent calls to the Yammer API\n\nIn order to provide this functionality, some setup must be done.\n\n\n**Setup**\n\nThe SDK is available at https://github.com/yammer/windows-phone-oauth-sdk-demo. It consists of two projects:\n\nYammer.OAuthSDK – is a Windows Phone 8 class library project that contains helper methods to help you handle the OAuth login and authorization process, as well as giving a head start of how to call an API once we have a token.\n\nOAuthWPDemo – is an actual Windows Phone 8 application that demonstrates how to setup and use these helper classes in an App.\n\nTo setup your own working app:\n\nStep 1) Register a new Yammer app that represents your Windows Phone app.\n\nStep 2) As part of the application setup in step 1, set the Redirect URI to a custom URI scheme. This must be unique to your WP8 app. Here’s an example: wp8oauthdemo://something. Make sure the scheme name (in this case “wp8oauthdemo”) is unique to your company and WP8 app.\n\nStep 3) You will need to create an instance of Yammer.OAuthSDK.Model.OAuthClientInfo with your app’s values, obtained when registering your app above. The best place to do this is on the Application resource dictionary in your App.xaml file e.g.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!--Application Resources-->\\n<Application.Resources>\\n  <!- ... ->\\n  <model:OAuthClientInfo xmlns:model=\\\"clr-namespace:Yammer.OAuthSDK.Model;assembly=Yammer.OAuthSDK\\\" x:Key=\\\"MyOAuthClientInfo\\\"\\n      ClientId=\\\"XXXXXXXXXXXXXX\\\" \\n      ClientSecret=\\\"YYYYYYYYYYYYYYYYYYYY\\\" \\n      RedirectUri=\\\"wp8oauthdemo://something\\\" />\\n</Application.Resources>\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nNote the creation of a Property getter to facilitate access to this object Application-wide in App.xaml.cs:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/// <summary>\\n/// Easy access to the OAuth Client information defined in the App resource dictionary.\\n/// </summary>\\npublic OAuthClientInfo MyOAuthClientInfo\\n{\\n    get\\n    {\\n        return Resources[\\\"MyOAuthClientInfo\\\"] as OAuthClientInfo;\\n    }\\n}\\n \",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nStep 4) During the login process, users will be directed to the mobile IE web browser. In order for the browser to be able to switch back to your WP app, the custom URL Scheme from step 2 must be registered in the WP application. Here’s how you do that:\n\nTo register for a URI association, you must edit WMAppManifest.xml using the XML (Text) Editor. In Solution Explorer, expand the Properties folder and right-click the WMAppManifest.xml file, and then click Open With. In the Open With window, select XML(Text) Editor, and then click OK.\n\nIn the Extensions element of the app manifest file, a URI association is specified with a Protocol element (note that the Extensions element must immediately follow the Tokens element). Your Extensions element should look like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<Extensions>\\n  <Protocol Name=\\\"wp8oauthdemo\\\" NavUriFragment=\\\"encodedLaunchUri=%s\\\" TaskID=\\\"_default\\\" />\\n</Extensions>\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nAlso make sure to override the default URI-mapper class with our OAuth URI handler in the InitializePhoneApplication() method in App.xaml.cs:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Override the default URI-mapper class with our OAuth URI handler.\\nRootFrame.UriMapper = new OAuthResponseUriMapper(MyOAuthClientInfo.RedirectUri);\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n**Initiate User Login**\n\nAfter that you should be ready to go. Take a look at how the method is implemented and used in MainPage.xaml.cs::btnSignInWithYammer_Click. That’s the method that launches the IE browser and lets the user both authenticate, and Authorize the app.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"OAuthUtils.LaunchSignIn(string clientId, string redirectUri)\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n\n**Handle Redirect**\n\nNext, take a look at this which is used in MainPage.xaml.cs::OnNavigatedTo after a user has been redirected back from the Login/Authorization page.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"OAuthUtils.HandleApprove(string clientId,\\n            string clientSecret,\\n            string code, \\n            string state,\\n            Action onSuccess, \\n            Action onCSRF = null, \\n            Action<AuthenticationResponse> onErrorResponse = null, \\n            Action<Exception> onException = null)\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n**Make A Yammer REST API Call**\n\nFinally, note the use of this in MainPage.xaml.cs::btnCallFollowingApi_Click to handle the simple dump of a json result of an API call after the user has been successfully authenticated.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"OAuthUtils.GetJsonFromApi(Uri endpoint, \\n            Action<string> onSuccess, \\n            Action<AuthenticationResponse> onErrorResponse = null, \\n            Action<Exception> onException = null)\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nNote: \nOnce the server sees that a user has clicked the Allow button, future login requests do not display the page with the Allow button. This is a one time occurrence for each unique user/yammer-app combination. Subsequent login attempts will return directly to the WP8 app without the Allow page. You can manually Revoke Access to your app by going to https://www.yammer.com/account/applications.\n[block:embed]\n{\n  \"html\": \"<iframe src=\\\"http://docs.google.com/viewer?url=https://about.yammer.com/success/wp-content/uploads/sites/13/yammer_admin_guide_en_US.pdf&embedded=true\\\" width=\\\"600\\\" height=\\\"780\\\" style=\\\"border: none;\\\"></iframe>\",\n  \"url\": \"https://about.yammer.com/success/wp-content/uploads/sites/13/yammer_admin_guide_en_US.pdf\",\n  \"title\": null,\n  \"favicon\": null\n}\n[/block]","excerpt":"","slug":"windows-phone-8-sdk","type":"basic","title":"Windows Phone 8 SDK"}

Windows Phone 8 SDK


The Windows Phone 8 SDK provides you with the code necessary to integrate Yammer functionality into Windows Phone apps. It enables the following: 1. Allows users to do an OAuth 2 login to the Yammer network using the IE browser 2. Obtains an authToken and stores it securely to the Isolated Storage 3. Uses that authToken to make all subsequent calls to the Yammer API In order to provide this functionality, some setup must be done. **Setup** The SDK is available at https://github.com/yammer/windows-phone-oauth-sdk-demo. It consists of two projects: Yammer.OAuthSDK – is a Windows Phone 8 class library project that contains helper methods to help you handle the OAuth login and authorization process, as well as giving a head start of how to call an API once we have a token. OAuthWPDemo – is an actual Windows Phone 8 application that demonstrates how to setup and use these helper classes in an App. To setup your own working app: Step 1) Register a new Yammer app that represents your Windows Phone app. Step 2) As part of the application setup in step 1, set the Redirect URI to a custom URI scheme. This must be unique to your WP8 app. Here’s an example: wp8oauthdemo://something. Make sure the scheme name (in this case “wp8oauthdemo”) is unique to your company and WP8 app. Step 3) You will need to create an instance of Yammer.OAuthSDK.Model.OAuthClientInfo with your app’s values, obtained when registering your app above. The best place to do this is on the Application resource dictionary in your App.xaml file e.g. [block:code] { "codes": [ { "code": "<!--Application Resources-->\n<Application.Resources>\n <!- ... ->\n <model:OAuthClientInfo xmlns:model=\"clr-namespace:Yammer.OAuthSDK.Model;assembly=Yammer.OAuthSDK\" x:Key=\"MyOAuthClientInfo\"\n ClientId=\"XXXXXXXXXXXXXX\" \n ClientSecret=\"YYYYYYYYYYYYYYYYYYYY\" \n RedirectUri=\"wp8oauthdemo://something\" />\n</Application.Resources>", "language": "text" } ] } [/block] Note the creation of a Property getter to facilitate access to this object Application-wide in App.xaml.cs: [block:code] { "codes": [ { "code": "/// <summary>\n/// Easy access to the OAuth Client information defined in the App resource dictionary.\n/// </summary>\npublic OAuthClientInfo MyOAuthClientInfo\n{\n get\n {\n return Resources[\"MyOAuthClientInfo\"] as OAuthClientInfo;\n }\n}\n ", "language": "text" } ] } [/block] Step 4) During the login process, users will be directed to the mobile IE web browser. In order for the browser to be able to switch back to your WP app, the custom URL Scheme from step 2 must be registered in the WP application. Here’s how you do that: To register for a URI association, you must edit WMAppManifest.xml using the XML (Text) Editor. In Solution Explorer, expand the Properties folder and right-click the WMAppManifest.xml file, and then click Open With. In the Open With window, select XML(Text) Editor, and then click OK. In the Extensions element of the app manifest file, a URI association is specified with a Protocol element (note that the Extensions element must immediately follow the Tokens element). Your Extensions element should look like this: [block:code] { "codes": [ { "code": "<Extensions>\n <Protocol Name=\"wp8oauthdemo\" NavUriFragment=\"encodedLaunchUri=%s\" TaskID=\"_default\" />\n</Extensions>", "language": "text" } ] } [/block] Also make sure to override the default URI-mapper class with our OAuth URI handler in the InitializePhoneApplication() method in App.xaml.cs: [block:code] { "codes": [ { "code": "// Override the default URI-mapper class with our OAuth URI handler.\nRootFrame.UriMapper = new OAuthResponseUriMapper(MyOAuthClientInfo.RedirectUri);", "language": "text" } ] } [/block] **Initiate User Login** After that you should be ready to go. Take a look at how the method is implemented and used in MainPage.xaml.cs::btnSignInWithYammer_Click. That’s the method that launches the IE browser and lets the user both authenticate, and Authorize the app. [block:code] { "codes": [ { "code": "OAuthUtils.LaunchSignIn(string clientId, string redirectUri)", "language": "text" } ] } [/block] **Handle Redirect** Next, take a look at this which is used in MainPage.xaml.cs::OnNavigatedTo after a user has been redirected back from the Login/Authorization page. [block:code] { "codes": [ { "code": "OAuthUtils.HandleApprove(string clientId,\n string clientSecret,\n string code, \n string state,\n Action onSuccess, \n Action onCSRF = null, \n Action<AuthenticationResponse> onErrorResponse = null, \n Action<Exception> onException = null)", "language": "text" } ] } [/block] **Make A Yammer REST API Call** Finally, note the use of this in MainPage.xaml.cs::btnCallFollowingApi_Click to handle the simple dump of a json result of an API call after the user has been successfully authenticated. [block:code] { "codes": [ { "code": "OAuthUtils.GetJsonFromApi(Uri endpoint, \n Action<string> onSuccess, \n Action<AuthenticationResponse> onErrorResponse = null, \n Action<Exception> onException = null)", "language": "text" } ] } [/block] Note: Once the server sees that a user has clicked the Allow button, future login requests do not display the page with the Allow button. This is a one time occurrence for each unique user/yammer-app combination. Subsequent login attempts will return directly to the WP8 app without the Allow page. You can manually Revoke Access to your app by going to https://www.yammer.com/account/applications. [block:embed] { "html": "<iframe src=\"http://docs.google.com/viewer?url=https://about.yammer.com/success/wp-content/uploads/sites/13/yammer_admin_guide_en_US.pdf&embedded=true\" width=\"600\" height=\"780\" style=\"border: none;\"></iframe>", "url": "https://about.yammer.com/success/wp-content/uploads/sites/13/yammer_admin_guide_en_US.pdf", "title": null, "favicon": null } [/block]