-
Notifications
You must be signed in to change notification settings - Fork 104
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
ERROR -- omniauth: (apple) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: {"error":"invalid_request"} #110
Comments
After enabling additional logging on the OAuth2 gem, I found that the request to INFO -- request: POST https://appleid.apple.com/auth/token |
@wonderffle were you able to resolve the above error? |
I just opened a PR to update the documentation for Hybrid application(Rails API and JS client) which I think answers your question, would you mind having a look and telling whether that helps you or not ? Basically the issue I had which sounds quite similar to yours is that I was sending my data the request's body fetch('https://my.api.domain/users/auth/apple/callback', {
data: JSON.stringify({ code }),
headers: { 'Content-Type': 'application/json' },
method: 'POST'
}) but what I discovered is that Instead what I had to do was send the data as query params and that fixed the fetch(`https://my.api.domain/users/auth/apple/callback?code=${code}`, {
headers: { 'Content-Type': 'application/json' },
method: 'POST'
}) |
I keep running into the following error in my
OmniauthCallbacksController
which inherits fromDevise::OmniauthCallbacksController
. On the front end, I am using the auth-code flow to authenticate users with their Apple ID and then I pass the code and the redirect_uri as body parameters to this devise endpoint. However, I am getting the following error:ERROR -- omniauth: (apple) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: {"error":"invalid_request"}
This method works fine with google oauth2, but it's failing for me with Apple.
Perhaps I am missing some configuration or other step, however, I can authenticate with the auth code using the apple_id gem.
Here are some details of my configuration below:
rails version: 7.0.6
devise version: 4.9.2
omniauth-apple version: 1.3.0
devise.rb
`
config.omniauth :google_oauth2, OMNIAUTH_GOOGLE_CLIENT_ID, OMNIAUTH_GOOGLE_CLIENT_SECRET, scope: 'email,profile', provider_ignores_state: true
config.omniauth :apple, OMNIAUTH_APPLE_CLIENT_ID, '', {
scope: 'email name',
team_id: OMNIAUTH_APPLE_TEAM_ID,
key_id: OMNIAUTH_APPLE_KEY_ID,
pem: OMNIAUTH_APPLE_PRIVATE_KEY,
provider_ignores_state: true,
authorized_client_ids: [ OMNIAUTH_APPLE_CLIENT_ID ],
redirect_uri: 'https://lvh.me/login'
}
`
routes.rb
devise_for :users, controllers: { sessions: 'sessions', registrations: 'registrations', omniauth_callbacks: 'users/omniauth_callbacks' }, defaults: { format: :json }
user.rb
devise :database_authenticatable, :confirmable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :jwt_authenticatable, :omniauthable, jwt_revocation_strategy: JwtBlacklist, omniauth_providers: [:apple, :google_oauth2]
The text was updated successfully, but these errors were encountered: