/// <summary> /// Generates a new access token given the authorization code generated by the page /// at get_auth_url(). /// /// In the context of a web server, the programmer should retrieve the auth_code /// generated by the page at get_auth_url() and use it as the input to this function. /// The programmer should then use the string returned from this function to /// authenticate calls to the API library on behalf of the corresponding user. /// /// Note: The following URLs must be identical: /// This function's redirect parameter /// The redirect parameter passed to get_access_token /// One of the redirect URIs listed on the app setup page /// </summary> /// <param name="authCode">The authorization code given in the 'code' query parameter of the page URI after redirecting from the result of get_auth_url</param> /// <param name="cid">The client ID for the current app</param> /// <param name="secret">The client secret for the current app</param> /// <param name="redirect">The redirect URI for the app (see note)</param> /// <param name="apiRoot">The root url of the API being used (in OldVimeoClient, accessible via config['apiroot'])</param> /// <returns>Access Token JSON. result["access_token"].ToString() contains access token in string</returns> public static Dictionary <string, object> GetAccessToken( string authCode, string cid, string secret, string redirect, string apiRoot) { string encoded = Helpers.ToBase64(String.Format("{0}:{1}", cid, secret)); Debug.WriteLine(String.Format("Encoded: {0}", encoded)); var payload = new Dictionary <string, string> { { "grant_type", "authorization_code" }, { "code", authCode }, { "redirect_uri", redirect } }; var headers = new WebHeaderCollection()// Dictionary<string, string> { //{"Accept", "application/vnd.vimeo.*+json; version=3.2"}, { "Authorization", String.Format("Basic {0}", encoded) } }; var response = Helpers.HTTPFetch( String.Format("{0}/oauth/access_token", apiRoot), "POST", headers, payload); return(new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(response)); }
/// <summary> /// Generates a bearer token for the registered application. /// This token will exist without a user context, but will allow for access to data in the API. /// </summary> /// <param name="clientId">The client ID for the current app</param> /// <param name="clientSecret">The client secret for the current app</param> /// <param name="scopes">A list of permission scopes that the user will be prompted to allow</param> /// <param name="apiRoot">The root url of the API being used (in OldVimeoClient, accessible via config['apiroot'])</param> /// <returns>a bearer token for the registered application.</returns> public static string GetClientCredentials(string clientId, string clientSecret, string scopes = null, string apiRoot = "https://api.vimeo.com") { var basicAuth = Helpers.ToBase64(String.Format("{0}:{1}", clientId, clientSecret)); var payload = new Dictionary <string, string> { { "grant_type", "client_credentials" } }; var headers = new WebHeaderCollection { //{"Accept", "application/vnd.vimeo.*+json; version=3.2"}, { "Authorization", String.Format("Basic {0}", basicAuth) } }; if (scopes != null) { payload.Add("scope", scopes); } var response = Helpers.HTTPFetch(String.Format("{0}/oauth/authorize/client", apiRoot), "POST", headers, payload); var json = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(response); return(json["access_token"]); }