phcdevworks_accounts_stytch 0.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c563b7ded4134aa0d9dfec2c7752d8bd906acc4e0ae5e7c0cdcba0329826ce0b
4
+ data.tar.gz: 8eb6102a8d03caf22d873c7dee953fe0e0e504ba1ddd56447b56221ea495e1a3
5
+ SHA512:
6
+ metadata.gz: 14c8913938b0b496cd581711c88e23a591687e05d05189b774c6b7ad05324db31ae9d466969ec480561d5ac00566ddb922e5934dd8911b1c1fd1bc0238dd4526
7
+ data.tar.gz: '04829407918f5ce3b36dac18852065b559fdee68032fe4a2325e683127788c67474924a769f117be7cc236a0d4dab8a85c2d316977766cce5fd60abaaa3803cf'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Bradley J Potts
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # PhcdevworksAccountsStytch
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "phcdevworks_accounts_stytch"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install phcdevworks_accounts_stytch
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
+
8
+ load 'rails/tasks/statistics.rake'
9
+
10
+ require 'bundler/gem_tasks'
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/phcdevworks_accounts_stytch .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ # app/controllers/phcdevworks_accounts_stytch/authentication/login_controller.rb
2
+ # frozen_string_literal: true
3
+
4
+ require 'phcdevworks_accounts_stytch/stytch_client'
5
+
6
+ module PhcdevworksAccountsStytch
7
+ module Authentication
8
+ class LoginController < ApplicationController
9
+ include StytchClient
10
+
11
+ def create
12
+ email = params[:email]
13
+ response = send_magic_link(email)
14
+ render json: response
15
+ rescue StandardError => e
16
+ render json: { error: e.message }, status: :internal_server_error
17
+ end
18
+
19
+ private
20
+
21
+ def send_magic_link(email)
22
+ stytch_client.magic_links.email.discovery.send(email_address: email)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ module Authentication
5
+ class ProcessorController < ApplicationController
6
+ include StytchClient
7
+
8
+ def create
9
+ token = params[:token]
10
+ response = authenticate_token(token)
11
+ render_success(response)
12
+ rescue StandardError => e
13
+ render_error(e)
14
+ end
15
+
16
+ private
17
+
18
+ def authenticate_token(token)
19
+ stytch_client.magic_links.discovery.authenticate(discovery_magic_links_token: token)
20
+ end
21
+
22
+ def render_success(response)
23
+ render plain: success_message(response)
24
+ end
25
+
26
+ def render_error(error)
27
+ render plain: error.message, status: :unauthorized
28
+ end
29
+
30
+ def success_message(response)
31
+ "Hello, #{response.email_address}! Complete the Discovery flow by creating an " \
32
+ "Organization with your intermediate session token: #{response.intermediate_session_token}."
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ module ApplicationHelper
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ class ApplicationJob < ActiveJob::Base
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ class ApplicationMailer < ActionMailer::Base
5
+ default from: 'from@example.com'
6
+ layout 'mailer'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Phcdevworks accounts stytch</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "phcdevworks_accounts_stytch/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ PhcdevworksAccountsStytch::Engine.routes.draw do
4
+ namespace :authentication do
5
+ post 'login', to: 'login#create'
6
+ post 'process', to: 'processor#create'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace PhcdevworksAccountsStytch
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StytchClient
4
+ def stytch_client
5
+ @stytch_client ||= StytchB2B::Client.new(
6
+ project_id: StytchClientConfig.project_id,
7
+ secret: StytchClientConfig.secret
8
+ )
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhcdevworksAccountsStytch
4
+ VERSION = '0.1.0.pre.1'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'phcdevworks_accounts_stytch/version'
4
+ require 'phcdevworks_accounts_stytch/engine'
5
+
6
+ # PhcdevworksAccountsStytch
7
+ # This module serves as the namespace for the PhcdevworksAccountsStytch engine.
8
+ module PhcdevworksAccountsStytch
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :phcdevworks_accounts_stytch do
5
+ # # Task goes here
6
+ # end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phcdevworks_accounts_stytch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.1
5
+ platform: ruby
6
+ authors:
7
+ - PHCDevworks
8
+ - Brad Potts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-07-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '7.1'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 7.1.3.4
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '7.1'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.1.3.4
34
+ - !ruby/object:Gem::Dependency
35
+ name: stytch
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '9.1'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '9.1'
48
+ description: PHCDevworks Accounts Stytch is a Ruby on Rails Engine for Stytch Authentication.
49
+ email:
50
+ - info@phcdevworks.com
51
+ - brad.potts@phcdevworks.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - MIT-LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - app/assets/config/phcdevworks_accounts_stytch_manifest.js
60
+ - app/assets/stylesheets/phcdevworks_accounts_stytch/application.css
61
+ - app/controllers/phcdevworks_accounts_stytch/application_controller.rb
62
+ - app/controllers/phcdevworks_accounts_stytch/authentication/login_controller.rb
63
+ - app/controllers/phcdevworks_accounts_stytch/authentication/processor_controller.rb
64
+ - app/helpers/phcdevworks_accounts_stytch/application_helper.rb
65
+ - app/jobs/phcdevworks_accounts_stytch/application_job.rb
66
+ - app/mailers/phcdevworks_accounts_stytch/application_mailer.rb
67
+ - app/models/phcdevworks_accounts_stytch/application_record.rb
68
+ - app/views/layouts/phcdevworks_accounts_stytch/application.html.erb
69
+ - config/routes.rb
70
+ - lib/phcdevworks_accounts_stytch.rb
71
+ - lib/phcdevworks_accounts_stytch/engine.rb
72
+ - lib/phcdevworks_accounts_stytch/stytch_client.rb
73
+ - lib/phcdevworks_accounts_stytch/version.rb
74
+ - lib/tasks/phcdevworks_accounts_stytch_tasks.rake
75
+ homepage: https://phcdevworks.com/
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org/
80
+ homepage_uri: https://phcdevworks.com/
81
+ source_code_uri: https://github.com/phcdevworks/phcdevworks_accounts_stytch/
82
+ changelog_uri: https://github.com/phcdevworks/phcdevworks_accounts_stytch/releases/
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.7.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.1
97
+ requirements: []
98
+ rubygems_version: 3.3.27
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Rails Engine for Stytch Authentication
102
+ test_files: []