Coder Social home page Coder Social logo

Comments (7)

darkyen avatar darkyen commented on June 9, 2024

Hi John,

What is the meta-data that you are trying to fetch? You can add metadata to the idToken which is returned by the lib as idTokenPayload alternatively, you can make a call to the /userinfo endpoint in both the cases any non standard metadata will needed to be added to the profile / idToken as described at https://auth0.com/docs/rules/current#copy-user-metadata-to-id-token

from auth0-cordova.

JohnMcLear avatar JohnMcLear commented on June 9, 2024

not /userInfo (I think), I have that working great thanks!

I am talking about the "user_metadata" value that auth0 exposes.

I'm still getting to grips with auth0 but as the admin interface states the user has write control over this value and with this in mind I'm looking for it to be an easy way for a user to store and retrieve a simple value.

I was expecting something like..

auth0.client.set("user_metadata", {foo: "bar"}, function(){});

Like I said I'm a huge noob to auth0 but I don't feel like https://auth0.com/docs/rules/current#copy-user-metadata-to-id-token does this... Happy to be proven wrong though!

from auth0-cordova.

Pita avatar Pita commented on June 9, 2024

Hello,

I'm working with John on this project. We basicly want to store a bit of data with each user, its just a string basicly, its all the information we need to store for a user for our specific use case.

I read a bit through the API docs. I understand how we can set meta data via the management API. But I don't understand yet how to read it via the Authentication API. Ideally we could retrieve the metadata at any moment, long after the initial authentication happened. Is this possible? I looked a bit into rules and idtoken but didn't manage to wrap my head around it.

Hope that clearifies things a bit

Peter

from auth0-cordova.

JohnMcLear avatar JohnMcLear commented on June 9, 2024

We decided to workaround auth0 in this instance (somewhat) by just using the bearer and sub..

Here is the example code we used to set and get metadata...

You will need to set SUB and IDTOKEN -- these values are available in the auth0.client object.

First we SET(PATCH) the value..

    var url = "https://DOMAIN.auth0.com/api/v2/users/"+SUB;
    $.ajax({
      method: "PATCH",
      url: url,
      data: {
        user_metadata: {
          whatever: "somevalue"
        }
      },
      headers: {
        'authorization': "Bearer "+IDTOKEN
      },
      success: function(d){
        console.log("success", d);
      },
      error: function(e){
        console.log("error getting metadata", e)
      }
    })

and here we GET the value..

    var url = "https://DOMAIN.auth0.com/api/v2/users/"+SUB+"?fields=user_metadata";
    $.get({
      url: url,
      headers: {
        'authorization': "Bearer "+IDTOKEN
      },
      success: function(d){
        console.log("success", d)
        if(d.user_metadata){
          console.log(d.user_metadata); // should be {whatever: "somevalue"}
        }
      },
      error: function(e){
        console.log("error getting metadata", e)
      }
    })

Sorry if we took a slightly hacky approach but it works and we can manage it so... If auth0 want to provide a cleaner approach that fits more inline with the API I'm all ears :)

from auth0-cordova.

darkyen avatar darkyen commented on June 9, 2024

Hi John, This is a historically legacy feature that works for now (basically allows you to have current_user) access through the ID_Token in future you should be able to get tokens for Management API directly with the scope for current_user. I'll get back to you with the blueprint for that.

from auth0-cordova.

JohnMcLear avatar JohnMcLear commented on June 9, 2024

Thanks I'd like to make sure I'm not using something that will be deprecated in x months! :)

from auth0-cordova.

JohnMcLear avatar JohnMcLear commented on June 9, 2024

Bump :)

from auth0-cordova.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.