{"_id":"54739056007eb108007e0421","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"},"githubsync":"","parentDoc":null,"project":"545137a814af501a00b50cf9","user":"5433099f9a2b451a00ad4531","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"},"__v":5,"updates":["556e01913f11b01900a3693d","57cef55e2aeb7b0e00ab43e5"],"next":{"pages":[],"description":""},"createdAt":"2014-11-24T20:08:54.452Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"try":true,"basic_auth":false,"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":4,"body":"Install the NuGet package by searching for Yammer in the Nuget Package Manager UI in Visual Studio, or by typing Install-Package Yammer.Oss.Api in the Package Manager Console.\n\nThis will install the Yammer SDK libraries together with a few dependencies.\n\nNote: there are a few instances where not all the packages will get installed, if that’s the case, you can add them manually by right-clicking in the ‘References’ folder of your project, click on ‘Add a Reference’. Then you can browse to the packages folder (usually at the same level of the solution file), go into the packages\\Yammer.Oss.Api\\lib\\{platform}\\{configuration} and add the files manually.\n\nThe Core files need to be added too and they are found in \\packages\\Yammer.Oss.Api\\lib\\portable-net45+netcore45+wp8+win8\\{configuration}.\n\n\n**Initialization Process**\n\nDependency Injection\nFor ease of configurability, it’s recommended to use a dependency Injection/Inversion-Of-Control framework such as Unity to handle the automatic initialization of the main SDK objects (repositories, clients, serializer) in charge of making the communications back and forth to the Yammer API endpoints seamless. You can copy this code in your App.xaml.cs file and call the _configureIoC() in your initialization routine.\n\n\n**Initialize SDK Objects**\n\nIn the code samples we use the Unity IoC Framework to handle the lifespan of the core objects. Below is an example of how this can be done (and this is how the sample code does too):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private IUnityContainer _container;\\n        private void _configureIoC()\\n        {\\n            _configureIocOAuth();\\n            _configureIocClients();\\n        }\\n\\n        private void _configureIocOAuth()\\n        {\\n            _container = new UnityContainer();\\n\\n            _container\\n                .RegisterSingletonType()\\n                .RegisterInstance(new JsonDotNetSerializer())\\n                .RegisterInstance(new JsonDotNetDeserializer())\\n                .RegisterInstance(WebRequest.DefaultWebProxy)\\n                .RegisterSingletonType();\\n\\n            _container\\n                .RegisterInstance(new ClientConfiguration(\\n                    MyOAuthClientInfo,\\n                    ProductInfoHeaderValue.Parse(\\\"Yammer_Activities_ModenApp/1.0.0.0\\\"),\\n                    MyYammerUris));\\n\\n            _container.RegisterSingletonType(\\n                new InjectionConstructor(typeof(IClientConfiguration),\\n                    typeof(IQueryStringSerializer),\\n                    typeof(ISerializer),\\n                    typeof(IDeserializer),\\n                    _container.Resolve(),\\n                    typeof(ICookieStore),\\n                    typeof(IWebProxy)));\\n        }\\n        private void _configureIocClients()\\n        {\\n                _container.RegisterSingletonType(\\n                    new InjectionConstructor(typeof(IClientConfiguration),\\n                                             typeof(IQueryStringSerializer),\\n                                             typeof(ISerializer),\\n                                             typeof(IDeserializer),\\n                                             _container.Resolve(),\\n                                             typeof(ICookieStore),\\n                                             typeof(IWebProxy)))\\n                .RegisterSingletonType(\\n                    new InjectionConstructor(typeof(IClientConfiguration),\\n                                             typeof(IQueryStringSerializer),\\n                                             typeof(ISerializer),\\n                                             typeof(IDeserializer),\\n                                             _container.Resolve(),\\n                                             typeof(ICookieStore),\\n                                             typeof(IWebProxy)))\\n                .RegisterSingletonType(\\n                    new InjectionConstructor(typeof(IClientConfiguration),\\n                                             typeof(IQueryStringSerializer),\\n                                             typeof(ISerializer),\\n                                             typeof(IDeserializer),\\n                                             _container.Resolve(),\\n                                             typeof(ICookieStore),\\n                                             typeof(IWebProxy)))\\n                .RegisterSingletonType(\\n                    new InjectionConstructor(typeof(IClientConfiguration),\\n                                             typeof(IQueryStringSerializer),\\n                                             typeof(ISerializer),\\n                                             typeof(IDeserializer),\\n                                             _container.Resolve(),\\n                                             typeof(ICookieStore),\\n                                             typeof(IWebProxy)));\\n\\n\\n            _container\\n                .RegisterSingletonType()\\n                .RegisterSingletonType()\\n                .RegisterSingletonType()\\n                .RegisterSingletonType()\\n                .RegisterSingletonType()\\n                .RegisterSingletonType();\\n        }\\n\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe advantage of using a container such as Unity (like in the code above) is that it will take care of the lifecycle of your objects, and also handle the singleton objects as needed. (Note: the RegisterSingletonType method use here, it’s an extension method we have created on top of the Unity container for ease of use).\n\nOnce all these objects are initialized, you’re pretty much ready to start using the SDK and integrating Yammer functionality into your app.\n\n\n**OAuth In .NET SDK**\n\nThis is the first step to integrate Yammer in your app. The SDK provides a couple of methods that enable a very fast Authentication process development, but in case you’re are curious about what happens behind the scenes, the full process is described here.\n\nWindows 8\nMake sure you have enabled the following capabilities in your Windows 8 App:\n\n– Enterprise Authentication\n\n– Internet (Client)\n\n– Private Networks (Client & Server)\n\n– Shared User Certificates\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/sgquhyhRPCHuTnpXQ3F6_yammerdotnetsdk-300x228.png\",\n        \"yammerdotnetsdk-300x228.png\",\n        \"300\",\n        \"228\",\n        \"#2a475e\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nTo do this, double-click the Package.appx manifest and click on the Capabilities tab as shown above.\n\nNote: The SDK uses the WebAuthenticationBroker to enable the OAuth2 signup process including networks requiring SSO login.\n\nOpen the App.xaml file and in the ResourceDictionary add the following objects:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nFor the OAuthClientInfo, it is EXTREMELY IMPORTANT that the information in every field matches exactly what’s on the web (including the RedirectUri), otherwise the authentication will fail.\n\nThe second object (YammerBaseUris) copy as is.\n\nIn the code behind file (App.xaml.cs) add the following getters:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public OAuthClientInfo MyOAuthClientInfo\\n{\\n\\tget\\n\\t{\\n\\t\\treturn Resources[\\\"MyOAuthClientInfo\\\"] as OAuthClientInfo;\\n\\t}\\n}\\n\\npublic YammerBaseUris MyYammerUris\\n\\t{\\n\\tget\\n\\t{\\n\\t\\t\\treturn Resources[\\\"MyYammerUris\\\"] as YammerBaseUris;\\n\\t}\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThese will help retrieve the values from the resource dictionary.\n\n\n**Standard Process**\n\nThe code to do the OAuth process is basically 2 lines of code (the 3rd line is only used to store the information in the StateManager object to be able to call the other YAMMER API endpoints):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled);\\nvar credentials = await _authRepository.AuthenticateAppAsync(authResponse.Code);\\nUpdateState(credentials);\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThis is the method’s definition:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private async Task UpdateState(Credentials credentials)\\n{\\n\\tif (credentials == null)\\n\\t\\tthrow new UnauthorizedException(\\\"Invalid Credentials\\\", HttpStatusCode.SeeOther);\\n \\n\\tStateManager.Credentials = credentials;\\n\\tStateManager.CurrentUser = null;\\n\\tStateManager.CurrentUser = await _userRepository.GetCurrentUserAsync();\\n\\tif (credentials != null)\\n\\t\\tNavigationService.Navigate();\\n\\tIsBusy = false;\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n**Single Sign On (SSO)**\n\nWhen Single Sign On is required, the AuthenticateAppAsync call will throw an exception of type SSOEnabledException. This makes the process of handling SSO Authentication easier. Below is one way of doing it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public async void Login()\\n{\\n\\tHasErrored = false;\\n\\tIsBusy = true;     bool ssoEnabled = false;     try     {         await AuthorizationProcessAsync(ssoEnabled);     }     catch (Exception ex)     {         ssoEnabled = ex is SSOEnabledException;     }     if (ssoEnabled)     {         try         {             await AuthorizationProcessAsync(ssoEnabled);         }         catch (Exception ex)         {            var inEx = ex.InnerException ?? ex;             _eventAggregator.Publish(new ServerErrorMessage(inEx.Message));        }     }\\n}\\n \\nprivate async Task AuthorizationProcessAsync(bool ssoEnabled)\\n{      var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled);      var credentials = await _authRepository.AuthenticateAppAsync(authResponse.Code);      UpdateState(credentials);\\n}\\n\\n \",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n**Getting Help**\n\nThis is an open source project and is provided \"as is\" without official support. It is not supported through Microsoft customer support channels. If you would like help you can post to [Stack Overflow](http://www.stackoverflow.com), or review the [source code](https://github.com/yammer/dotnet-yammersdk) on GitHub.","excerpt":"","slug":"net-sdk","type":"basic","title":".NET SDK"}
Install the NuGet package by searching for Yammer in the Nuget Package Manager UI in Visual Studio, or by typing Install-Package Yammer.Oss.Api in the Package Manager Console. This will install the Yammer SDK libraries together with a few dependencies. Note: there are a few instances where not all the packages will get installed, if that’s the case, you can add them manually by right-clicking in the ‘References’ folder of your project, click on ‘Add a Reference’. Then you can browse to the packages folder (usually at the same level of the solution file), go into the packages\Yammer.Oss.Api\lib\{platform}\{configuration} and add the files manually. The Core files need to be added too and they are found in \packages\Yammer.Oss.Api\lib\portable-net45+netcore45+wp8+win8\{configuration}. **Initialization Process** Dependency Injection For ease of configurability, it’s recommended to use a dependency Injection/Inversion-Of-Control framework such as Unity to handle the automatic initialization of the main SDK objects (repositories, clients, serializer) in charge of making the communications back and forth to the Yammer API endpoints seamless. You can copy this code in your App.xaml.cs file and call the _configureIoC() in your initialization routine. **Initialize SDK Objects** In the code samples we use the Unity IoC Framework to handle the lifespan of the core objects. Below is an example of how this can be done (and this is how the sample code does too): [block:code] { "codes": [ { "code": "private IUnityContainer _container;\n private void _configureIoC()\n {\n _configureIocOAuth();\n _configureIocClients();\n }\n\n private void _configureIocOAuth()\n {\n _container = new UnityContainer();\n\n _container\n .RegisterSingletonType()\n .RegisterInstance(new JsonDotNetSerializer())\n .RegisterInstance(new JsonDotNetDeserializer())\n .RegisterInstance(WebRequest.DefaultWebProxy)\n .RegisterSingletonType();\n\n _container\n .RegisterInstance(new ClientConfiguration(\n MyOAuthClientInfo,\n ProductInfoHeaderValue.Parse(\"Yammer_Activities_ModenApp/1.0.0.0\"),\n MyYammerUris));\n\n _container.RegisterSingletonType(\n new InjectionConstructor(typeof(IClientConfiguration),\n typeof(IQueryStringSerializer),\n typeof(ISerializer),\n typeof(IDeserializer),\n _container.Resolve(),\n typeof(ICookieStore),\n typeof(IWebProxy)));\n }\n private void _configureIocClients()\n {\n _container.RegisterSingletonType(\n new InjectionConstructor(typeof(IClientConfiguration),\n typeof(IQueryStringSerializer),\n typeof(ISerializer),\n typeof(IDeserializer),\n _container.Resolve(),\n typeof(ICookieStore),\n typeof(IWebProxy)))\n .RegisterSingletonType(\n new InjectionConstructor(typeof(IClientConfiguration),\n typeof(IQueryStringSerializer),\n typeof(ISerializer),\n typeof(IDeserializer),\n _container.Resolve(),\n typeof(ICookieStore),\n typeof(IWebProxy)))\n .RegisterSingletonType(\n new InjectionConstructor(typeof(IClientConfiguration),\n typeof(IQueryStringSerializer),\n typeof(ISerializer),\n typeof(IDeserializer),\n _container.Resolve(),\n typeof(ICookieStore),\n typeof(IWebProxy)))\n .RegisterSingletonType(\n new InjectionConstructor(typeof(IClientConfiguration),\n typeof(IQueryStringSerializer),\n typeof(ISerializer),\n typeof(IDeserializer),\n _container.Resolve(),\n typeof(ICookieStore),\n typeof(IWebProxy)));\n\n\n _container\n .RegisterSingletonType()\n .RegisterSingletonType()\n .RegisterSingletonType()\n .RegisterSingletonType()\n .RegisterSingletonType()\n .RegisterSingletonType();\n }\n", "language": "text" } ] } [/block] The advantage of using a container such as Unity (like in the code above) is that it will take care of the lifecycle of your objects, and also handle the singleton objects as needed. (Note: the RegisterSingletonType method use here, it’s an extension method we have created on top of the Unity container for ease of use). Once all these objects are initialized, you’re pretty much ready to start using the SDK and integrating Yammer functionality into your app. **OAuth In .NET SDK** This is the first step to integrate Yammer in your app. The SDK provides a couple of methods that enable a very fast Authentication process development, but in case you’re are curious about what happens behind the scenes, the full process is described here. Windows 8 Make sure you have enabled the following capabilities in your Windows 8 App: – Enterprise Authentication – Internet (Client) – Private Networks (Client & Server) – Shared User Certificates [block:image] { "images": [ { "image": [ "https://files.readme.io/sgquhyhRPCHuTnpXQ3F6_yammerdotnetsdk-300x228.png", "yammerdotnetsdk-300x228.png", "300", "228", "#2a475e", "" ] } ] } [/block] To do this, double-click the Package.appx manifest and click on the Capabilities tab as shown above. Note: The SDK uses the WebAuthenticationBroker to enable the OAuth2 signup process including networks requiring SSO login. Open the App.xaml file and in the ResourceDictionary add the following objects: [block:code] { "codes": [ { "code": "", "language": "text" } ] } [/block] For the OAuthClientInfo, it is EXTREMELY IMPORTANT that the information in every field matches exactly what’s on the web (including the RedirectUri), otherwise the authentication will fail. The second object (YammerBaseUris) copy as is. In the code behind file (App.xaml.cs) add the following getters: [block:code] { "codes": [ { "code": "public OAuthClientInfo MyOAuthClientInfo\n{\n\tget\n\t{\n\t\treturn Resources[\"MyOAuthClientInfo\"] as OAuthClientInfo;\n\t}\n}\n\npublic YammerBaseUris MyYammerUris\n\t{\n\tget\n\t{\n\t\t\treturn Resources[\"MyYammerUris\"] as YammerBaseUris;\n\t}\n}", "language": "text" } ] } [/block] These will help retrieve the values from the resource dictionary. **Standard Process** The code to do the OAuth process is basically 2 lines of code (the 3rd line is only used to store the information in the StateManager object to be able to call the other YAMMER API endpoints): [block:code] { "codes": [ { "code": "var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled);\nvar credentials = await _authRepository.AuthenticateAppAsync(authResponse.Code);\nUpdateState(credentials);", "language": "text" } ] } [/block] This is the method’s definition: [block:code] { "codes": [ { "code": "private async Task UpdateState(Credentials credentials)\n{\n\tif (credentials == null)\n\t\tthrow new UnauthorizedException(\"Invalid Credentials\", HttpStatusCode.SeeOther);\n \n\tStateManager.Credentials = credentials;\n\tStateManager.CurrentUser = null;\n\tStateManager.CurrentUser = await _userRepository.GetCurrentUserAsync();\n\tif (credentials != null)\n\t\tNavigationService.Navigate();\n\tIsBusy = false;\n}", "language": "text" } ] } [/block] **Single Sign On (SSO)** When Single Sign On is required, the AuthenticateAppAsync call will throw an exception of type SSOEnabledException. This makes the process of handling SSO Authentication easier. Below is one way of doing it: [block:code] { "codes": [ { "code": "public async void Login()\n{\n\tHasErrored = false;\n\tIsBusy = true; bool ssoEnabled = false; try { await AuthorizationProcessAsync(ssoEnabled); } catch (Exception ex) { ssoEnabled = ex is SSOEnabledException; } if (ssoEnabled) { try { await AuthorizationProcessAsync(ssoEnabled); } catch (Exception ex) { var inEx = ex.InnerException ?? ex; _eventAggregator.Publish(new ServerErrorMessage(inEx.Message)); } }\n}\n \nprivate async Task AuthorizationProcessAsync(bool ssoEnabled)\n{ var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled); var credentials = await _authRepository.AuthenticateAppAsync(authResponse.Code); UpdateState(credentials);\n}\n\n ", "language": "text" } ] } [/block] **Getting Help** This is an open source project and is provided "as is" without official support. It is not supported through Microsoft customer support channels. If you would like help you can post to [Stack Overflow](http://www.stackoverflow.com), or review the [source code](https://github.com/yammer/dotnet-yammersdk) on GitHub.