Giter VIP home page Giter VIP logo

Comments (9)

wildan2711 avatar wildan2711 commented on July 27, 2024 1

Thank you for pointing to https://jwt.io !

I was able to resolve my claims using that, it looks something like this:

{
  "iss": "https://securetoken.google.com/app",
  "name": "wildancok",
  "id": "60b664d7-9fa6-4c87-b412-b61db20542414",
  "aud": "app",
  "auth_time": 1504352839,
  "user_id": "4ee4daIofZZpjMBdiaEk8PyONAg1",
  "sub": "4ee4dsdo9ZZpjMBdiaEk8PyONAg1",
  "iat": 1504352839,
  "exp": 1504356439,
  "email": "[email protected]",
  "email_verified": false,
  "phone_number": "+1111111111",
  "firebase": {
    "identities": {
      "phone": [
        "+1111111111111"
      ],
      "email": [
        "[email protected]"
      ]
    },
    "sign_in_provider": "custom"
  }
}

I only need the id field. It seems the claims became into one struct containing all the custom fields. So I modified your firebase.Claims struct into this:

type Claims struct {
	Issuer    string      `json:"iss,omitempty"`
	Subject   string      `json:"sub,omitempty"`
	Audience  string      `json:"aud,omitempty"`
	IssuedAt  int64       `json:"iat,omitempty"`
	ExpiresAt int64       `json:"exp,omitempty"`
	UserID    string      `json:"uid,omitempty"`
	ID        string      `json:"id,omitempty"`
	Claims    interface{} `json:"claims,omitempty"`
}

Then my tests passed! So how would I go about providing a custom claim struct for token verification? Because whenever I update dependencies using dep it would revert my changes to this library.

Thank you very much!

from go-firebase-admin.

wildan2711 avatar wildan2711 commented on July 27, 2024 1

Okay thank you for the clarification and help. I had different ideas in using the custom token than the official firebase docs you just showed. Maybe I just fork your library just for my use case.

Thank you once again, and sorry for my misunderstanding..

from go-firebase-admin.

acoshift avatar acoshift commented on July 27, 2024

Hi,
firebase.auth().currentUser.getIdToken() in client library not include claims in its body.
You can try test your access token in https://jwt.io

from go-firebase-admin.

wildan2711 avatar wildan2711 commented on July 27, 2024

I was expecting an answer on "how would I go about providing a custom claim struct for token verification? ",

from go-firebase-admin.

acoshift avatar acoshift commented on July 27, 2024

Yes!, I'll working on this tonight.
and maybe change type Claims struct { into type Token struct {

from go-firebase-admin.

acoshift avatar acoshift commented on July 27, 2024

Not sure why you need custom claims when verify id token, because firebase access token has its own structure.
Maybe I just add more fields to hold all access token data.

from go-firebase-admin.

wildan2711 avatar wildan2711 commented on July 27, 2024

hmm.. So what is the point of creating a custom token with additional claims? What is the use case of additional claims?

from go-firebase-admin.

acoshift avatar acoshift commented on July 27, 2024

custom token is use for sign in on client (browser) to talk with security rules in firebase database.
see https://firebase.google.com/docs/auth/admin/create-custom-tokens#create_custom_tokens_using_a_third-party_jwt_library

from go-firebase-admin.

acoshift avatar acoshift commented on July 27, 2024

IMO, I very sure that when you sign in with custom token, firebase store custom token claims on their server.
btw, you CAN NOT use token from create custom token in verify id token, because It use difference claims structure.

from go-firebase-admin.

Related Issues (19)

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.