deskoh / feathers-authentication-oidc

Feathers OpenID Connect authentication strategy using OIDC Provider issued JWT
6 stars 1 forks source link

_id instead oidcId #72

Closed equa2k9 closed 1 year ago

equa2k9 commented 2 years ago

What I want to do, is to set _id the same as in jwt token instead of additional property oidcId, is it possible or will be better to extend and modify class?

deskoh commented 2 years ago

The default key is {strategyName}Id. If you want to set it to _id it is not guaranteed to be unique. i.e. there could be potential clashes.

This strategy follows heavily with OAuthStrategy (https://docs.feathersjs.com/api/authentication/oauth.html#oauthstrategy) which looks up entities based on ${this.name}Id. It is better to inherit and modify the class IMO.

equa2k9 commented 2 years ago

Thanks for answer, is it provide some caching? What I want to know: When in hooks I provide authentication('oidc') and call this service with jwt token that provided by oidc, is it call auth service every request or just first time?

deskoh commented 1 year ago

if using REST, when the hooks run, the following function would execute.

https://github.com/deskoh/feathers-authentication-oidc/blob/v0.4.4/src/OidcStrategy.ts#L159

As REST calls are stateless, it would not be able to distinguish the first calls from subsequent calls. Of particular interest is the updateEntity flag, which is meant to be set to true to update user info into the user store.

Does that address your query?

equa2k9 commented 1 year ago

I'm just ovveride Oidc strategy functions

import { OidcStrategy } from 'feathers-authentication-oidc';

export class AdvancedOidcStrategy extends OidcStrategy {
  async getEntityQuery(decodedJwt) {
    return {
      ['_id']: decodedJwt.sub || decodedJwt.id
    }
  }
  async getEntityData(decodedJwt, _params) {
    let entity = {
      ['_id']: decodedJwt.sub || decodedJwt.id
    }
    const { additionalFields } = this.configuration
    if (additionalFields) {
      for (const field of additionalFields) {
        entity[field] = decodedJwt[field]
      }
    }
    return entity
  }
}