https://github.com/agility/generateugcaccesshash-netcore
A utility to initialize the UGC Access Hash on the server, before passing it to the client.
https://github.com/agility/generateugcaccesshash-netcore
Last synced: about 1 year ago
JSON representation
A utility to initialize the UGC Access Hash on the server, before passing it to the client.
- Host: GitHub
- URL: https://github.com/agility/generateugcaccesshash-netcore
- Owner: agility
- Created: 2019-01-02T20:46:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-02T21:07:08.000Z (over 7 years ago)
- Last Synced: 2025-02-14T04:51:16.312Z (over 1 year ago)
- Language: C#
- Size: 5.86 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# How to Generate a UGC Access Hash in .NET Core
In order to use the Agility UGC API, you need to generate your own Access Key. This should be done on the server for security purposes.
This repository includes a Utility function to generate your hash, and an HtmlHelper method to output those values server-side as a script and pass the values to use in a client application.
## Setup
1. Add the UGCUtils class to your project, and ensure you update the namespace appropriately.
2. Add the HtmlHelpers class to your project, and ensure you update the namespace appropriately.
3. Use the HtmlHelper in your _Layout.cshtml masterpage to ensure your client app can use these values on each page.
``` html
@using Website.Helpers
...
@RenderBody()
@Html.GetUGCDataServiceInitializationScript()
@RenderSection("Scripts", required: false)
...
```
*Will output:*
``` html
var _AgilityUGCSettings = {
'Url': 'https://ugc.agilitycms.com/Agility-UGC-API-JSONP.svc',
'AccessKey': '553901D2-F5E1-4BBA-B346-159xxxxxxx', //the website API Access Key provided to you
'Seconds': '567353588', //is the number of seconds that have elapsed since Jan 1/2001.
'RandomNumber': '205', //just a random number between 1-1000
'ProfileRecordID': '-1', //the profile record ID of the logged-in website user, -1 is anonymous
'AccessHash': '7c690bdac92defff3a676e24ded04c5xxxxxxx' //The SHA hash of all the above variables
//(Seconds.ProfileID.SecretKey.AccessKey.Random)
};
```
## Usage
As long as you have the _AgilityUGCSettings js global variable set, you can utilize the Agility UGC API. See the [UGC API](https://github.com/AgilityInc/Agility.UGC.API.js) for details.