-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub OAuth with identity_resource seems to be broken #555
Comments
What does |
[
%Ash.Resource.Attribute{
name: :refresh_token,
type: Ash.Type.String,
allow_nil?: true,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :refresh_token,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: [allow_empty?: false, trim?: true]
},
%Ash.Resource.Attribute{
name: :access_token_expires_at,
type: Ash.Type.UtcDatetimeUsec,
allow_nil?: true,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :access_token_expires_at,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: [precision: :microsecond, timezone: :utc]
},
%Ash.Resource.Attribute{
name: :access_token,
type: Ash.Type.String,
allow_nil?: true,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :access_token,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: [allow_empty?: false, trim?: true]
},
%Ash.Resource.Attribute{
name: :uid,
type: Ash.Type.String,
allow_nil?: false,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :uid,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: [allow_empty?: false, trim?: true]
},
%Ash.Resource.Attribute{
name: :strategy,
type: Ash.Type.String,
allow_nil?: false,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :strategy,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: [allow_empty?: false, trim?: true]
},
%Ash.Resource.Attribute{
name: :id,
type: Ash.Type.UUID,
allow_nil?: false,
generated?: false,
primary_key?: true,
private?: false,
writable?: true,
always_select?: false,
default: &Ash.UUID.generate/0,
update_default: nil,
description: nil,
source: :id,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: []
},
%Ash.Resource.Attribute{
name: :user_id,
type: Ash.Type.UUID,
allow_nil?: true,
generated?: false,
primary_key?: false,
private?: false,
writable?: true,
always_select?: false,
default: nil,
update_default: nil,
description: nil,
source: :user_id,
match_other_defaults?: false,
sensitive?: false,
filterable?: true,
constraints: []
}
] |
Interesting :) So the problem here is that the id from GH is an integer, and AshAuthentication expects a string. We can solve this one of two ways:
|
At what stage should I be updating |
You'd need to put something like this above change fn changeset, _ ->
new_user_info =
changeset
|> Ash.Changeset.get_argument(:user_info)
|> Map.update!("sub", &String.to_integer/1)
Ash.Changeset.set_argument(changeset, :user_info, new_user_info)
end |
It should be Integer.to_string/1 but otherwise it looks good. Thanks! For future reference, here is what I update my action to: create :register_with_github do
argument :user_info, :map, allow_nil?: false
argument :oauth_tokens, :map, allow_nil?: false
upsert? true
upsert_identity :unique_email
change fn changeset, _ ->
IO.puts("Debugging the changeset before:")
dbg(changeset)
end
# Required if you have token generation enabled.
change AshAuthentication.GenerateTokenChange
# Required if you have the `identity_resource` configuration enabled.
change AshAuthentication.Strategy.OAuth2.IdentityChange
change fn changeset, _ ->
IO.puts("Debugging the changeset after 1:")
dbg(changeset)
user_info =
Ash.Changeset.get_argument(changeset, :user_info)
|> Map.update!("sub", &Integer.to_string/1)
Ash.Changeset.change_attributes(changeset, Map.take(user_info, ["email"]))
|> Ash.Changeset.set_argument(:user_info, user_info)
|> dbg()
end |
I will leave the issue open till it is fixed in main 👍 |
Hi,
I followed the guides and was able to get the GitHub Oauth working. However, this was without the identity_resource being configured. Then I decided to configure the identity_resource and make use of that but now I am getting this error:
Here is the complete changeset:
This is how my
register_with_github
actions looks like:And this is how my user identity looks like:
The text was updated successfully, but these errors were encountered: