Skip to content
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

Fix oauth2 for net-smtp 0.4.0 #5

Closed
wants to merge 1 commit into from

Conversation

wnm
Copy link
Contributor

@wnm wnm commented Mar 19, 2024

In net-smtp 0.4.0, auth_* methods are moved out from the Net::SMTP class, see this PR. Instead you should create a new class that inherits from Net::SMTP::Authenticator. There is a PR already merged that adds a xoauth2 class to net-smtp. Until it gets released with a new version of net-smtp, lets add it to mail_xoauth2?

@wnm
Copy link
Contributor Author

wnm commented Mar 19, 2024

Not 100% sure if a new mail_xoauth gem version with this fix is the best way to go... if anyone gets a ArgumentError: wrong authentication type xoauth2 error after upgrading net-smtp to 0.4.0, the easiest fix is to add a xoauth2 autenticater class to /config/initializers/auth_xoauth2.rb:

class Net::SMTP
  class AuthXoauth2 < Net::SMTP::Authenticator
    auth_type :xoauth2

    def auth(user, secret)
      token = xoauth2_string(user, secret)

      finish("AUTH XOAUTH2 #{base64_encode(token)}")
    end

    private

    def xoauth2_string(user, secret)
      "user=#{user}\1auth=Bearer #{secret}\1\1"
    end
  end
end

@fjaeger
Copy link
Contributor

fjaeger commented Mar 27, 2024

@wnm As net-smtp version 0.5.0 is now released, how do you want to proceed with this PR?

@wnm
Copy link
Contributor Author

wnm commented Apr 16, 2024

thanks @fjaeger, yes I think this is no longer needed

@wnm wnm closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants