• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by karafs · Feb 01, 2017 at 11:05 AM · java

How to use JWT in unity?

Hi all. I want to use of JWT in unity. There is a gitlab project that help me. https://github.com/jwt-dotnet/jwt But I don't know how to work with it. Actually I don't know how to send data to the server first time and receive the user's JWT to use it later. In other word, I don't know how to implement the first section of below Image in unity. Can anybody help me please?

alt text

jwt-how-it-works.png (82.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image karafs · Feb 01, 2017 at 11:47 AM 0
Share

@johnsheehan @twilio @devinrader @firebase @abatishchev

avatar image karafs · Feb 01, 2017 at 11:53 AM 0
Share

@aditya @aditya007

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by KruegerT · Feb 01, 2017 at 11:15 AM

It's more of a server question than Unity. You will send a request to the server with for example the users mail (no JWT here). The server will then generate the JWT which you receive and save in Unity. In every other request you will send the JWT too and the server verifies that its valid.

An example PHP script:

 <?php 
 use \Firebase\JWT\JWT; //installed via Composer
 
 function Get($mail){
     $token = array(
         'iss' => 'YourName',
         'exp' => time() + 3600,    //valid for 1h
         'iat' => time(),
         'eml' => $mail,    //own value
     );
     return JWT::encode($token, JWTKey); //they secret key only your server knows
 }
 
 function Verify($token, $mail){
     try{
         $userDecoded = JWT::decode($token, JWTKey, array('HS256'));
         if(!isset($userDecoded->eml) ||
           strcmp($userDecoded->eml,$mail) != 0){
             http_response_code(417);
             exit;
         }else{
             return true;
         }
     }catch(\Exception $e){
         echo 'Caught exception: ',  $e->getMessage(), "\n";
         http_response_code(417);
         exit;
     }
 }
 ?>

Best,
Thomas

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joseGuate97 · Apr 22, 2020 at 01:10 AM 0
Share

I agree with this. As I understand it, there's no need for JWT libraries for unity because only the server needs to understand what it means. At least, that's the usual use case, right? Haven't implemented it yet but I'm planning to.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Im new so if you're ganna flame me then don't read this 2 Answers

How to load android activity when the button clicked in unity scene? 0 Answers

No Java runtime present, requesting install. 1 Answer

Move Button as soon as its klicked to the bottom Screen 1 Answer

Google Cast - Android Build fails 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges