Sha256: d61aadbda8e2d302c7fc2c87747abfabfcd825022b4ed85796e7d42699c62340

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Shimmer
  module Auth
    class AppleProvider < Provider
      self.token_column = :apple_id

      private

      def request_details(params)
        name = params[:user] ? JSON.parse(params[:user])["name"] : {}
        headers = {
          'Content-Type': "application/x-www-form-urlencoded"
        }
        form = {
          grant_type: "authorization_code",
          code: params[:code],
          client_id: Config.instance.apple_bundle_id!,
          client_secret: Config.instance.apple_client_secret,
          scope: "name email"
        }
        response = HTTParty.post("https://appleid.apple.com/auth/token", body: URI.encode_www_form(form), headers: headers)
        raise InvalidTokenError, "Login check failed: #{response.body}" unless response.ok?

        token = JWT.decode(response["id_token"], nil, false).first
        UserDetails.new token: token["sub"], email: token["email"], first_name: name["firstName"], last_name: name["lastName"]
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
shimmer-0.0.28 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.27 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.26 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.25 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.24 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.23 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.22 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.21 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.20 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.19 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.18 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.17 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.16 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.15 lib/shimmer/auth/apple_provider.rb
shimmer-0.0.14 lib/shimmer/auth/apple_provider.rb