mapkit_token 1.0.0

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: 45bea3e3d390b755069255b64c3d7feb217d8c724db38c3030403d1449cd01d9
4
+ data.tar.gz: ab38b4f43b735ce4ecd7ddca3d1a1a1453f6430489c85d1c2381b5ec71302413
5
+ SHA512:
6
+ metadata.gz: 3cae35f9190898e2101da404c1deeb600fa72d2a9d9d11a39b7c1fec7a7270bd2d78bcdace8156c00b5e11ed6a725e1d3094a595c4692bb14e49c29fe36e720f
7
+ data.tar.gz: d822fe17f5db923ce272321a6ecee1a403337f46b1e45ad24517b62e2a50c68823fa3bd75fb614b424a13614e38d69aa5dff68e67b919d75d591d63f711ed9e5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at medlund@mac.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mapkit_token.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # MapKit Token
2
+
3
+ MapKit JS uses JSON Web Tokens (JWTs) to authenticate map initializations and other API requests. This gem adds an endpoint to a Rails applications to provide MapKit JS with such authentication JWTs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mapkit_token'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mapkit_token
20
+
21
+ ## Usage
22
+
23
+ Before you can use this gem, you need a Maps Identifer (i.e., Maps ID) and private key that is associated to a Maps ID. If you haven't yet done that, read more about how to do that here:
24
+
25
+ [Creating a Maps Identifier and a Private Key](https://developer.apple.com/documentation/mapkitjs/creating_a_maps_identifier_and_a_private_key)
26
+
27
+ Add your AuthKey to your application folder, and make sure you have these pieces of information:
28
+
29
+ - Path to AuthKey
30
+ - MapKit JS Key ID
31
+ - Apple Developer Team ID
32
+
33
+ Edit your application credentials:
34
+
35
+ $ EDITOR=vim rails credentials:edit
36
+
37
+ In case you have different AuthKey files for your different environments, edit your environment credentials separately:
38
+
39
+ $ EDITOR=vim rails credentials:edit --environment development
40
+
41
+ Add your credentials:
42
+
43
+ ```yaml
44
+ mapkit:
45
+ auth_key_path: AuthKey_XXXXXXXXXX.p8
46
+ auth_key_id: XXXXXXXXXX
47
+ apple_team_id: XXXXXXXXXX
48
+ ```
49
+
50
+ After reloading your application, it will have a new endpoint `/mapkit_token` that returns JWTs that are valid for 30 minutes. The application's hostname is added to the JWT payload to specify that the tokens only can used by the application itself.
51
+
52
+ Use the endpoint for the `authorizationCallback` function that MapKit JS calls whenever it detects that a new token is needed.
53
+
54
+ ```html
55
+ <!DOCTYPE html>
56
+ <html>
57
+ ...
58
+ <div id="map" style="width: 800px; height: 600px;"></div>
59
+ <script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>
60
+ <script>
61
+ mapkit.init({ authorizationCallback: function(done) { fetch("/mapkit_token")
62
+ .then(res => res.text())
63
+ .then(token => done(token)) /* If successful, return your token to MapKit JS */
64
+ .catch(error => { /* Handle error */ });
65
+ }});
66
+ let map = new mapkit.Map("map", { center: new mapkit.Coordinate(59.329, 18.068) });
67
+ </script>
68
+ ...
69
+ </html>
70
+ ```
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mapkit_token. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the MapkitToken project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mapkit_token/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ module MapkitToken
2
+ class MapkitTokenController < ApplicationController
3
+
4
+ def mapkit
5
+ Rails.application.credentials.mapkit
6
+ end
7
+
8
+ def auth_key
9
+ File.read(mapkit[:auth_key_path])
10
+ end
11
+
12
+ def auth_key_id
13
+ mapkit[:auth_key_id]
14
+ end
15
+
16
+ def apple_team_id
17
+ mapkit[:apple_team_id]
18
+ end
19
+
20
+ def base_url
21
+ request.protocol + request.host
22
+ end
23
+
24
+ def show
25
+ render plain: Mapkit.token.generate(auth_key: auth_key, auth_key_id: auth_key_id, apple_team_id: apple_team_id, base_url: base_url)
26
+ end
27
+ end
28
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mapkit_token"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get '/mapkit_token', to: 'mapkit_token/mapkit_token#show'
3
+ end
@@ -0,0 +1,15 @@
1
+ require "active_support/all"
2
+ require "mapkit_token/version"
3
+ require "mapkit_token/app/models/mapkit.rb"
4
+ require "jwt"
5
+
6
+ module MapkitToken
7
+ mattr_accessor :app_root
8
+
9
+ def self.setup
10
+ yield self
11
+ end
12
+ end
13
+
14
+ require "mapkit_token/engine"
15
+
@@ -0,0 +1,25 @@
1
+ class Mapkit
2
+ @@instance = Mapkit.new
3
+ private_class_method :new
4
+
5
+ def self.token
6
+ return @@instance
7
+ end
8
+
9
+ def generate *args
10
+ return nil unless (creds = args.first).is_a?(Hash)
11
+
12
+ auth_key = creds[:auth_key]
13
+ auth_key_id = creds[:auth_key_id]
14
+ apple_team_id = creds[:apple_team_id]
15
+ base_url = creds[:base_url]
16
+ lifespan_seconds = creds[:lifespan] ||= 1800
17
+
18
+ header = {kid: auth_key_id, typ: "JWT", alg: "ES256"}
19
+ payload = {iss: apple_team_id, iat: DateTime.now.to_i, exp: DateTime.now.to_i + lifespan_seconds, origin: base_url}.compact
20
+ private_key = OpenSSL::PKey::EC.new(auth_key)
21
+ return JWT.encode payload, private_key, algorithm='ES256', header
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,4 @@
1
+ module MapkitToken
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module MapkitToken
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mapkit_token/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mapkit_token"
8
+ spec.version = MapkitToken::VERSION
9
+ spec.authors = ["Michael Edlund"]
10
+ spec.email = ["medlund@mac.com"]
11
+
12
+ spec.summary = %q{MapKit JS token endpoint provider.}
13
+ spec.homepage = "https://github.com/arcticleo/mapkit_token"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_dependency "activesupport"
27
+ spec.add_dependency "rails"
28
+ spec.add_dependency "jwt"
29
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mapkit_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Edlund
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jwt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - medlund@mac.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - app/controllers/mapkit_token/mapkit_token_controller.rb
112
+ - bin/console
113
+ - bin/setup
114
+ - config/routes.rb
115
+ - lib/mapkit_token.rb
116
+ - lib/mapkit_token/app/models/mapkit.rb
117
+ - lib/mapkit_token/engine.rb
118
+ - lib/mapkit_token/version.rb
119
+ - mapkit_token.gemspec
120
+ homepage: https://github.com/arcticleo/mapkit_token
121
+ licenses: []
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: MapKit JS token endpoint provider.
142
+ test_files: []