Files
growstuff/app/controllers/authentications_controller.rb
T
Brenda Wallace 78dd9625b8 Add Bluesky OAuth integration
- Implement Atproto::ClientConfig for managing OAuth client configuration.
- Create Atproto::Http module for handling HTTP requests with SSRF protection.
- Develop Atproto::Identity class to resolve handles to DIDs and validate DID documents.
- Introduce Atproto::Jws for generating and signing JWTs for OAuth.
- Create Atproto::OauthClient to manage the OAuth authorization flow with Bluesky.
- Add OmniAuth strategy for Bluesky sign-in, allowing users to authenticate using their Bluesky handle.
- Update views to include Bluesky sign-in options and handle connections.
- Modify routes to expose OAuth client metadata.
- Allow members to sign in without an email address when using Bluesky.
- Add tests for Bluesky authorization and sign-in processes.
2026-11-01 12:16:43 +13:00

56 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require './lib/actions/oauth_signup_action'
class AuthenticationsController < ApplicationController
before_action :authenticate_member!
load_and_authorize_resource
skip_load_and_authorize_resource only: :connected
# POST /authentications
def create
auth = request.env['omniauth.auth']
@authentication = nil
if auth
name = Growstuff::OauthSignupAction.new.determine_name(auth)
@authentication = current_member.authentications
.create_with(
name:,
token: auth['credentials']['token'],
secret: auth['credentials']['secret']
)
.find_or_create_by(
provider: auth['provider'],
uid: auth['uid'],
name:
)
flash[:notice] = t('messages.auth_success')
else
flash[:notice] = t('messages.auth_failed')
end
redirect_to request.env['omniauth.origin'] || edit_member_registration_path
end
# Where the pop-up that connects an account from a dialog ends up (see
# AddPhotoModal): it says how it went and closes itself. The dialog notices the
# connection by asking the server, so it doesn't depend on this page.
def connected
@connected = current_member.auth('flickr').present?
render layout: false
end
# DELETE /authentications/1
def destroy
if current_member.last_sign_in_method?(@authentication)
return redirect_to edit_member_registration_path, alert: t('messages.auth_last_sign_in')
end
@authentication.destroy
respond_to do |format|
format.html { redirect_to edit_member_registration_path }
end
end
end