Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

using c# instead of js

matthias_gubsch641matthias_gubsch641 Member, Developers Posts: 6 ✭✭
hallo,

was anybody successful in using c# instead of node.js with the apikey mechanism?
i tried it, but i'm failed. i was able to build exact the same authorization string than i have in js, but the only result i received was:
status 401, "Unauthenticated API request.
i'm using vs 2013, .NET 4.5 and  https://github.com/restsharp

any hint will be helpful

thanks

matthias
Tagged:

Best Answer

  • matthias_gubsch641matthias_gubsch641 Member, Developers Posts: 6 ✭✭
    Answer ✓
    many thanks for your answer, but all the hints you are mentioned, i've already found in the readme ...
    so i tried to collect some more information for you and during doing that i found the solution :-)
    js is using 
    authDate = (new Date()).toUTCString();
    i have used in c#
    authDate = String.Format("{0:r}", DateTime.Now);
    i'm here in germany, that's why i have a one hour difference.
    now i'm using 
     authDate = String.Format("{0:r}", DateTime.UtcNow)
    and everything is now working perfect !

Answers

  • awkawk Member, Onshape Employees, Developers Posts: 78
    We don't have a sample code/library for using the API Keys from C# I'm afraid - the node.js and python examples remain the best source of reference for now (https://github.com/onshape-public/apikey).

    There's also some additional details the help section of the Developer Portal - a particular thing to note are the components of the request and what is hashed along with the key to generate the API Key signature. The order and exact presentation of the values prior to generating the HMAC digest is important : Create a string by appending the following information in order. Each field should be separated by a newline (\n) character, and the string must be converted to lowercase:
    1. HTTP method
    2. On-Nonce header value
    3. Date header value
    4. Content-Type header value
    5. URL pathname
    6. URL query string
    The On-Nonce value should be unique for every request and at least 16 characters of alphanumeric data.

    You don't mention what API you're trying to call - but remember the API keys have a 'scope' (like OAuth) so if your key doesn't have a scope for the permissions required by the API it may fail (though in this case I think you're key generation is at fault since you get the 401 response).

    Director of API, Appstore, and App Partner Technical Support
  • matthias_gubsch641matthias_gubsch641 Member, Developers Posts: 6 ✭✭
    Answer ✓
    many thanks for your answer, but all the hints you are mentioned, i've already found in the readme ...
    so i tried to collect some more information for you and during doing that i found the solution :-)
    js is using 
    authDate = (new Date()).toUTCString();
    i have used in c#
    authDate = String.Format("{0:r}", DateTime.Now);
    i'm here in germany, that's why i have a one hour difference.
    now i'm using 
     authDate = String.Format("{0:r}", DateTime.UtcNow)
    and everything is now working perfect !
Sign In or Register to comment.