auth0 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -19
- data/Gemfile +1 -1
- data/README.md +92 -38
- data/lib/auth0/api/authentication_endpoints.rb +169 -133
- data/lib/auth0/api/v2/client_grants.rb +8 -3
- data/lib/auth0/api/v2/clients.rb +9 -6
- data/lib/auth0/api/v2/connections.rb +16 -7
- data/lib/auth0/api/v2/rules.rb +6 -2
- data/lib/auth0/api/v2/users.rb +17 -14
- data/lib/auth0/version.rb +1 -1
- data/spec/integration/lib/auth0/api/api_authentication_spec.rb +28 -45
- data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +18 -15
- data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +19 -3
- data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +13 -17
- data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +24 -13
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +160 -57
- data/spec/lib/auth0/api/v2/client_grants_spec.rb +17 -2
- data/spec/lib/auth0/api/v2/clients_spec.rb +50 -5
- data/spec/lib/auth0/api/v2/connections_spec.rb +45 -1
- data/spec/lib/auth0/api/v2/rules_spec.rb +23 -1
- data/spec/lib/auth0/api/v2/users_spec.rb +19 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/spec_helper_full.rb +1 -2
- metadata +50 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e2d0aa18336dc8b5427ef196eebe49f8232e2776c90307d1c38e2129d8704e8
|
4
|
+
data.tar.gz: acfe0224309b9b2de3faa249f65e40654586f446494b53044d27cea4ad60b5da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194975ab5dce4b26bae48fdf25b143a7ae7ff47898e500dc0a49913bcecb54276919e79a70a8a5b2d1d064d176f15cd394bd58d26241f2388c35535ebf5614a5
|
7
|
+
data.tar.gz: 29bde6a3792287ecae9d8559e0b52ed8fc57407a183665944e1883cb3ee64dede9169a8525b191042c86b6c05a2833b34b592d60ff58ec97161d427fa4b84f49
|
data/CHANGELOG.md
CHANGED
@@ -1,42 +1,78 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v4.
|
4
|
-
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.
|
5
|
-
|
6
|
-
Note: If you are using the `login` endpoint, you will need to enable the [Resource Owner Password Grant](https://auth0.com/docs/clients/client-grant-types).
|
3
|
+
## [v4.5.0](https://github.com/auth0/ruby-auth0/tree/v4.5.0) (2018-07-26)
|
4
|
+
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.4.0...v4.5.0)
|
7
5
|
|
8
6
|
**Closed issues:**
|
9
7
|
|
10
|
-
-
|
11
|
-
https://github.com/auth0/ruby-auth0/issues/
|
8
|
+
- New version with updated rest-client dependency [\#93](https://github.com/auth0/ruby-auth0/issues/93)
|
9
|
+
- Bug?: `result` from auth0/mixins/httpproxy.rb returns 'nil' [\#88](https://github.com/auth0/ruby-auth0/issues/88)
|
10
|
+
- import\_users fails with EOFError [\#56](https://github.com/auth0/ruby-auth0/issues/56)
|
11
|
+
- Using inside of a Rails API [\#55](https://github.com/auth0/ruby-auth0/issues/55)
|
12
|
+
- Add documentation? [\#102](https://github.com/auth0/ruby-auth0/issues/102)
|
13
|
+
- logout\_url does not include client\_id parameter [\#81](https://github.com/auth0/ruby-auth0/issues/81)
|
14
|
+
|
15
|
+
**Merged pull requests:**
|
16
|
+
|
17
|
+
- Correctly default grant\_type to 'password' in login method [\#107](https://github.com/auth0/ruby-auth0/pull/107) ([psparrow](https://github.com/psparrow))
|
18
|
+
- Add additional parameters for WS-Fed URL [\#123](https://github.com/auth0/ruby-auth0/pull/123) ([joshcanhelp](https://github.com/joshcanhelp))
|
19
|
+
- Deprecate Authentication API endpoints [\#121](https://github.com/auth0/ruby-auth0/pull/121) ([joshcanhelp](https://github.com/joshcanhelp))
|
20
|
+
- Clean up auth endpoint tests [\#120](https://github.com/auth0/ruby-auth0/pull/120) ([joshcanhelp](https://github.com/joshcanhelp))
|
21
|
+
- Fix docblocks for Authentication API endpoints [\#119](https://github.com/auth0/ruby-auth0/pull/119) ([joshcanhelp](https://github.com/joshcanhelp))
|
22
|
+
- Add Client ID to logout\_url [\#118](https://github.com/auth0/ruby-auth0/pull/118) ([joshcanhelp](https://github.com/joshcanhelp))
|
23
|
+
- Add pagination and tests for Rules endpoint [\#117](https://github.com/auth0/ruby-auth0/pull/117) ([joshcanhelp](https://github.com/joshcanhelp))
|
24
|
+
- Add pagination and tests for Client Grants [\#116](https://github.com/auth0/ruby-auth0/pull/116) ([joshcanhelp](https://github.com/joshcanhelp))
|
25
|
+
- Add search\_engine parameter to Users endpoint + tests [\#115](https://github.com/auth0/ruby-auth0/pull/115) ([joshcanhelp](https://github.com/joshcanhelp))
|
26
|
+
- Improve README [\#114](https://github.com/auth0/ruby-auth0/pull/114) ([joshcanhelp](https://github.com/joshcanhelp))
|
27
|
+
- Add pagination and tests to Clients and Connections endpoints [\#113](https://github.com/auth0/ruby-auth0/pull/113) ([joshcanhelp](https://github.com/joshcanhelp))
|
28
|
+
- Use Secure RubyGems Source [\#112](https://github.com/auth0/ruby-auth0/pull/112) ([markprovan](https://github.com/markprovan))
|
12
29
|
|
13
|
-
|
14
|
-
https://github.com/auth0/ruby-auth0/
|
30
|
+
## [v4.4.0](https://github.com/auth0/ruby-auth0/tree/v4.4.0) (2018-02-19)
|
31
|
+
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.3.0...v4.4.0)
|
32
|
+
|
33
|
+
**Closed issues:**
|
15
34
|
|
16
|
-
-
|
17
|
-
https://github.com/auth0/ruby-auth0/issues/75
|
35
|
+
- Authentication Login is using `/oauth/ro`. [\#89](https://github.com/auth0/ruby-auth0/issues/89)
|
18
36
|
|
19
|
-
|
20
|
-
https://github.com/auth0/ruby-auth0/
|
37
|
+
## [v4.3.0](https://github.com/auth0/ruby-auth0/tree/v4.3.0) (2018-02-19)
|
38
|
+
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.2.0...v4.3.0)
|
21
39
|
|
22
40
|
**Merged pull requests:**
|
23
41
|
|
42
|
+
- Fix script publish gem [\#106](https://github.com/auth0/ruby-auth0/pull/106) ([alexisluque](https://github.com/alexisluque))
|
24
43
|
- Add support to /api/v2/users-by-email [\#105](https://github.com/auth0/ruby-auth0/pull/105) ([edgurgel](https://github.com/edgurgel))
|
44
|
+
- Update /login to use /oauth/token [\#94](https://github.com/auth0/ruby-auth0/pull/94) ([Zensaburou](https://github.com/Zensaburou))
|
45
|
+
- Fix error in the readme regarding timeouts [\#90](https://github.com/auth0/ruby-auth0/pull/90) ([ksamc](https://github.com/ksamc))
|
25
46
|
|
26
47
|
## [v4.2.0](https://github.com/auth0/ruby-auth0/tree/v4.2.0) (2018-02-15)
|
27
48
|
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.1.0...v4.2.0)
|
28
49
|
|
29
50
|
**Closed issues:**
|
30
51
|
|
31
|
-
- Vulnerable dependency: yard
|
32
|
-
https://github.com/auth0/ruby-auth0/issues/
|
52
|
+
- Vulnerable dependency: yard [\#99](https://github.com/auth0/ruby-auth0/issues/99)
|
53
|
+
- post\_password\_change results in payload validation error [\#84](https://github.com/auth0/ruby-auth0/issues/84)
|
54
|
+
- Unsupported on latest ruby version \(2.4.0\) [\#83](https://github.com/auth0/ruby-auth0/issues/83)
|
55
|
+
- Adding a resource server breaks authentication. [\#76](https://github.com/auth0/ruby-auth0/issues/76)
|
56
|
+
- outdated dependencies in ror-api example [\#75](https://github.com/auth0/ruby-auth0/issues/75)
|
33
57
|
|
34
|
-
|
35
|
-
https://github.com/auth0/ruby-auth0/issues/83
|
36
|
-
|
37
|
-
- Outdated dependencies in ror-api example. [\#75]
|
38
|
-
https://github.com/auth0/ruby-auth0/issues/75
|
58
|
+
**Merged pull requests:**
|
39
59
|
|
60
|
+
- Add scripts and Dockerfile to publish SDK on rubygems [\#104](https://github.com/auth0/ruby-auth0/pull/104) ([alexisluque](https://github.com/alexisluque))
|
61
|
+
- Fix typo [\#103](https://github.com/auth0/ruby-auth0/pull/103) ([coisnepe](https://github.com/coisnepe))
|
62
|
+
- Fix tests [\#101](https://github.com/auth0/ruby-auth0/pull/101) ([alexisluque](https://github.com/alexisluque))
|
63
|
+
- Update outdated dependency [\#100](https://github.com/auth0/ruby-auth0/pull/100) ([alexisluque](https://github.com/alexisluque))
|
64
|
+
- Fix build [\#98](https://github.com/auth0/ruby-auth0/pull/98) ([alexisluque](https://github.com/alexisluque))
|
65
|
+
- Add delay to integration test [\#97](https://github.com/auth0/ruby-auth0/pull/97) ([alexisluque](https://github.com/alexisluque))
|
66
|
+
- Fix build [\#96](https://github.com/auth0/ruby-auth0/pull/96) ([alexisluque](https://github.com/alexisluque))
|
67
|
+
- Removed reference to API v1 [\#91](https://github.com/auth0/ruby-auth0/pull/91) ([aaguiarz](https://github.com/aaguiarz))
|
68
|
+
- Update rest-client version to v2 [\#87](https://github.com/auth0/ruby-auth0/pull/87) ([hzalaz](https://github.com/hzalaz))
|
69
|
+
- Introduce and raise exception for timeout [\#85](https://github.com/auth0/ruby-auth0/pull/85) ([anderslemke](https://github.com/anderslemke))
|
70
|
+
- corrected missing comma in example code of readme.md [\#79](https://github.com/auth0/ruby-auth0/pull/79) ([drewnichols](https://github.com/drewnichols))
|
71
|
+
- Resolve v1 API example error [\#78](https://github.com/auth0/ruby-auth0/pull/78) ([jesseproudman](https://github.com/jesseproudman))
|
72
|
+
- updated dependencies in ror api example. Fix \#75 [\#77](https://github.com/auth0/ruby-auth0/pull/77) ([Amialc](https://github.com/Amialc))
|
73
|
+
- Add a badge to documentation [\#74](https://github.com/auth0/ruby-auth0/pull/74) ([amingilani](https://github.com/amingilani))
|
74
|
+
- Typo [\#73](https://github.com/auth0/ruby-auth0/pull/73) ([amingilani](https://github.com/amingilani))
|
75
|
+
- Add how to generate documentation to the README.md + patch\_user [\#72](https://github.com/auth0/ruby-auth0/pull/72) ([ignaciojonas](https://github.com/ignaciojonas))
|
40
76
|
|
41
77
|
## [v4.1.0](https://github.com/auth0/ruby-auth0/tree/v4.1.0) (2016-07-25)
|
42
78
|
[Full Changelog](https://github.com/auth0/ruby-auth0/compare/v4.0.0...v4.1.0)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,76 +1,130 @@
|
|
1
|
-
Ruby api client for [Auth0](https://auth0.com) platform
|
2
|
-
|
3
1
|
[![Build Status](https://travis-ci.org/auth0/ruby-auth0.svg?branch=master)](https://travis-ci.org/auth0/ruby-auth0)
|
4
2
|
[![Gem Version](https://badge.fury.io/rb/auth0.svg)](http://badge.fury.io/rb/auth0)
|
5
3
|
[![Coverage Status](https://coveralls.io/repos/auth0/ruby-auth0/badge.svg?branch=master)](https://coveralls.io/r/auth0/ruby-auth0?branch=master)
|
6
|
-
[![Dependency Status](https://gemnasium.com/auth0/ruby-auth0.svg)](https://gemnasium.com/auth0/ruby-auth0)
|
7
4
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/auth0/ruby-auth0/master/frames)
|
8
5
|
|
6
|
+
Ruby API client for the [Auth0](https://auth0.com) platform.
|
7
|
+
|
9
8
|
## Installation
|
10
9
|
|
10
|
+
This gem can be installed directly:
|
11
|
+
|
11
12
|
``` bash
|
12
13
|
$ gem install auth0
|
13
14
|
```
|
14
15
|
|
15
|
-
or with [Bundler](
|
16
|
+
... or with [Bundler](https://bundler.io/man/bundle-add.1.html):
|
16
17
|
|
17
|
-
```
|
18
|
-
|
18
|
+
```bash
|
19
|
+
bundle add auth0
|
19
20
|
```
|
20
21
|
|
21
|
-
##
|
22
|
+
## API Documentation
|
22
23
|
|
23
|
-
|
24
|
+
You can build the API documentation with the following:
|
24
25
|
|
25
|
-
```
|
26
|
-
|
26
|
+
``` bash
|
27
|
+
bundle exec rake documentation
|
28
|
+
```
|
27
29
|
|
28
|
-
|
29
|
-
:client_id => "YOUR CLIENT ID",
|
30
|
-
:token => "YOUR JWT HERE",
|
31
|
-
:domain => "<YOUR ACCOUNT>.auth0.com",
|
32
|
-
:api_version => 2
|
33
|
-
)
|
30
|
+
To view the generated documentation, open `doc/Auth0/Api.html`
|
34
31
|
|
35
|
-
|
36
|
-
```
|
32
|
+
## Management API v2
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
This SDK provides access to the [Management API v2](https://auth0.com/docs/api/management/v2) via modules that help create clear and accurate calls. Most of the interaction is done through the `Auth0Client` class, instantiated with the required credentials.
|
35
|
+
|
36
|
+
As a simple example of how to get started, we'll create an admin route to point to a list of all users from Auth0:
|
40
37
|
|
41
38
|
```ruby
|
42
|
-
|
39
|
+
# config/routes.rb
|
40
|
+
Rails.application.routes.draw do
|
41
|
+
# ...
|
42
|
+
get 'admin/users', to: 'all_users#index'
|
43
|
+
# ...
|
44
|
+
end
|
45
|
+
```
|
43
46
|
|
44
|
-
|
45
|
-
:client_id => "YOUR CLIENT ID",
|
46
|
-
:token => "YOUR JWT HERE",
|
47
|
-
:domain => "<YOUR ACCOUNT>.auth0.com",
|
48
|
-
:timeout => 15
|
49
|
-
)
|
47
|
+
... and a Controller to handle that route:
|
50
48
|
|
51
|
-
|
49
|
+
```ruby
|
50
|
+
# app/controllers/all_users_controllers.rb
|
51
|
+
require 'auth0'
|
52
|
+
|
53
|
+
class AllUsersController < ApplicationController
|
54
|
+
# Get all users from Auth0 with "auth0" in their email.
|
55
|
+
def index
|
56
|
+
@params = {
|
57
|
+
q: "email:*auth0*",
|
58
|
+
fields: 'email,user_id,name',
|
59
|
+
include_fields: true,
|
60
|
+
page: 0,
|
61
|
+
per_page: 50
|
62
|
+
}
|
63
|
+
@users = auth0_client.users @params
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Setup the Auth0 API connection.
|
69
|
+
def auth0_client
|
70
|
+
@auth0_client ||= Auth0Client.new(
|
71
|
+
client_id: ENV['AUTH0_RUBY_CLIENT_ID'],
|
72
|
+
token: ENV['AUTH0_RUBY_API_TOKEN'],
|
73
|
+
domain: ENV['AUTH0_RUBY_DOMAIN'],
|
74
|
+
api_version: 2,
|
75
|
+
timeout: 15 # optional, defaults to 10
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
52
79
|
```
|
53
80
|
|
54
|
-
|
81
|
+
In this example, we're using environment variables to store the values needed to connect to Auth0 and authorize. The `token` used above is an API token for the Management API with the scopes required to perform a specific action (in this case `read:users`). These tokens can be [generated manually](https://auth0.com/docs/api/management/v2/tokens#get-a-token-manually) using a test Application or with the [Application](https://manage.auth0.com/#/applications) being used for your project.
|
55
82
|
|
56
|
-
|
83
|
+
Finally, we'll add a view to display the results:
|
57
84
|
|
58
|
-
```
|
59
|
-
|
85
|
+
```ruby
|
86
|
+
# app/views/all_users/index.html.erb
|
87
|
+
<h1>Users</h1>
|
88
|
+
<%= debug @params %>
|
89
|
+
<%= debug @users %>
|
60
90
|
```
|
61
91
|
|
62
|
-
|
92
|
+
This should show the parameters passed to the `users` method and a list of users that matched the query (or an empty array if none).
|
93
|
+
|
94
|
+
## Authentication
|
95
|
+
|
96
|
+
In addition to the Management API, this SDK also provides access to [Authentication API](https://auth0.com/docs/api/authentication) endpoints with the `Auth0::API::AuthenticationEndpoints` module. For basic login capability, we suggest using our OmniAuth stategy [detailed here](https://auth0.com/docs/quickstart/webapp/rails/01-login). Other authentication tasks currently supported are:
|
97
|
+
|
98
|
+
* Register a new user with a database connection using the `signup` method.
|
99
|
+
* Redirect a user to the universal login page for authentication using the `authorization_url` method.
|
100
|
+
* Log a user in to a highly trusted app with the [Resource Owner Password grant](https://auth0.com/docs/api-auth/tutorials/password-grant) using the `login` method.
|
101
|
+
* Exchange an authorization code for an access token on callback using the `obtain_user_tokens` method (see the note on state validation below).
|
102
|
+
* Send a change password email to a database connection user using the `change_password` method.
|
103
|
+
* Log a user out of Auth0 with the `logout_url` method.
|
104
|
+
|
105
|
+
**Important note on state validation**: If you choose to implement a login flow callback youself, it is important to generate and store a `state` value, pass that value to Auth0 in the `authorization_url` method, and validate it in your callback URL before calling `obtain_user_tokens`. For more information on state validation, [please see our documentation](https://auth0.com/docs/protocols/oauth2/oauth-state).
|
106
|
+
|
107
|
+
Please note that this module implements endpoints that might be deprecated for newer tenants. If you have any questions about how and when the endpoints should be used, consult the [documentation](https://auth0.com/docs/api/authentication) or ask in our [Community forums](https://community.auth0.com/tags/wordpress).
|
108
|
+
|
109
|
+
|
110
|
+
## More Information
|
111
|
+
|
112
|
+
* [Login using OmniAuth](https://auth0.com/docs/quickstart/webapp/rails/01-login)
|
113
|
+
* [API authentication in Ruby](https://auth0.com/docs/quickstart/backend/ruby)
|
114
|
+
* [API authentication in Rails](https://auth0.com/docs/quickstart/backend/rails)
|
115
|
+
* [Managing authentication with Auth0 (blog)](https://auth0.com/blog/rails-5-with-auth0/)
|
116
|
+
* [Ruby on Rails workflow with Docker (blog)](https://auth0.com/blog/ruby-on-rails-killer-workflow-with-docker-part-1/)
|
63
117
|
|
64
118
|
## What is Auth0?
|
65
119
|
|
66
120
|
Auth0 helps you to:
|
67
121
|
|
68
|
-
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce
|
122
|
+
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce** among others, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
|
69
123
|
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
|
70
124
|
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
|
71
|
-
* Support for generating signed [
|
72
|
-
* Analytics of how, when and where users are logging in.
|
73
|
-
* Pull data from other sources and add it to the user profile
|
125
|
+
* Support for generating signed [JSON Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
|
126
|
+
* Analytics of how, when, and where users are logging in.
|
127
|
+
* Pull data from other sources and add it to the user profile with [JavaScript rules](https://docs.auth0.com/rules).
|
74
128
|
|
75
129
|
## Create a free Auth0 Account
|
76
130
|
|
@@ -79,7 +133,7 @@ Auth0 helps you to:
|
|
79
133
|
|
80
134
|
## Issue Reporting
|
81
135
|
|
82
|
-
If you
|
136
|
+
If you find a bug or have a feature request, please report them in this repository's [Issues tab](https://github.com/auth0/ruby-auth0/issues). Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
|
83
137
|
|
84
138
|
## Author
|
85
139
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# rubocop:disable Metrics/ModuleLength
|
2
2
|
module Auth0
|
3
3
|
module Api
|
4
|
-
# {https://auth0.com/docs/
|
5
|
-
# Methods to use the
|
4
|
+
# {https://auth0.com/docs/api/authentication}
|
5
|
+
# Methods to use the Authentication API
|
6
6
|
module AuthenticationEndpoints
|
7
7
|
UP_AUTH = 'Username-Password-Authentication'.freeze
|
8
8
|
JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer'.freeze
|
9
9
|
|
10
|
-
#
|
11
|
-
# @see https://auth0.com/docs/
|
10
|
+
# Retrieve an access token.
|
11
|
+
# @see https://auth0.com/docs/api/authentication#client-credentials
|
12
12
|
# @param access_token [string] Social provider's access_token
|
13
13
|
# @param connection [string] Currently, this endpoint only works for Facebook, Google, Twitter and Weibo
|
14
14
|
# @return [json] Returns the access token
|
@@ -22,12 +22,12 @@ module Auth0
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
#
|
26
|
-
# @see https://auth0.com/docs/
|
25
|
+
# Get access and ID tokens using an Authorization Code.
|
26
|
+
# @see https://auth0.com/docs/api/authentication#authorization-code
|
27
|
+
# @param code [string] The access code obtained through passive authentication
|
28
|
+
# @param redirect_uri [string] Url to redirect after authorization
|
27
29
|
# @param connection [string] Currently, this endpoint only works for Facebook, Google, Twitter and Weibo
|
28
30
|
# @param scope [string] Defaults to openid. Can be 'openid name email', 'openid offline_access'
|
29
|
-
# @param redirect_uri [string] Url to redirect after authorization
|
30
|
-
# @param redirect_uri [string] The access code obtained through passive authentication
|
31
31
|
# @return [json] Returns the access_token and id_token
|
32
32
|
def obtain_user_tokens(code, redirect_uri, connection = 'facebook', scope = 'openid')
|
33
33
|
raise Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
|
@@ -44,15 +44,15 @@ module Auth0
|
|
44
44
|
post('/oauth/token', request_params)
|
45
45
|
end
|
46
46
|
|
47
|
-
#
|
48
|
-
# @see https://auth0.com/docs/
|
49
|
-
# @param username [string] Username
|
50
|
-
# @param password [string]
|
51
|
-
# @param scope [string] Defaults to openid. Can be 'openid name email', 'openid offline_access'
|
47
|
+
# Get access and ID tokens using Resource Owner Password.
|
48
|
+
# @see https://auth0.com/docs/api/authentication#resource-owner-password
|
49
|
+
# @param username [string] Username or email
|
50
|
+
# @param password [string] Password
|
52
51
|
# @param id_token [string] Token's id
|
53
|
-
# @param connection_name [string] Connection name
|
54
|
-
# Active Directory/LDAP, Windows Azure
|
55
|
-
# @
|
52
|
+
# @param connection_name [string] Connection name; use a database or
|
53
|
+
# passwordless connection, Active Directory/LDAP, Windows Azure or ADF
|
54
|
+
# @param options [hash] Additional options - :scope, :grant_type, :device
|
55
|
+
# @return [json] Returns the access_token and id_token
|
56
56
|
def login(username, password, id_token = nil, connection_name = UP_AUTH, options = {})
|
57
57
|
raise Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty?
|
58
58
|
raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
|
@@ -63,80 +63,180 @@ module Auth0
|
|
63
63
|
password: password,
|
64
64
|
scope: options.fetch(:scope, 'openid'),
|
65
65
|
connection: connection_name,
|
66
|
-
grant_type: options.fetch(:grant_type, password),
|
66
|
+
grant_type: options.fetch(:grant_type, 'password'),
|
67
67
|
id_token: id_token,
|
68
68
|
device: options.fetch(:device, nil)
|
69
69
|
}
|
70
70
|
post('/oauth/token', request_params)
|
71
71
|
end
|
72
72
|
|
73
|
-
#
|
74
|
-
# @see https://auth0.com/docs/
|
75
|
-
# @param email [string]
|
76
|
-
# @param password [string]
|
77
|
-
# @param connection_name [string]
|
73
|
+
# Sign up with a database connection using a username and password.
|
74
|
+
# @see https://auth0.com/docs/api/authentication#signup
|
75
|
+
# @param email [string] New user's email
|
76
|
+
# @param password [string] New user's password
|
77
|
+
# @param connection_name [string] Database connection name
|
78
78
|
# @return [json] Returns the created user
|
79
79
|
def signup(email, password, connection_name = UP_AUTH)
|
80
80
|
raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
|
81
81
|
raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
|
82
82
|
request_params = {
|
83
|
-
client_id: @client_id,
|
84
83
|
email: email,
|
84
|
+
password: password,
|
85
85
|
connection: connection_name,
|
86
|
-
|
86
|
+
client_id: @client_id
|
87
87
|
}
|
88
88
|
post('/dbconnections/signup', request_params)
|
89
89
|
end
|
90
90
|
|
91
|
-
#
|
92
|
-
#
|
93
|
-
# @see https://auth0.com/docs/
|
94
|
-
# @param email [string] User email
|
95
|
-
# @param password [string] User's new password
|
96
|
-
#
|
91
|
+
# Change a user's password or trigger a password reset email.
|
92
|
+
# @see https://auth0.com/docs/api/authentication#change-password
|
93
|
+
# @see https://auth0.com/docs/connections/database/password-change
|
94
|
+
# @param email [string] User's current email
|
95
|
+
# @param password [string] User's new password; empty to trigger a
|
96
|
+
# password reset email
|
97
|
+
# @param connection_name [string] Database connection name
|
97
98
|
def change_password(email, password, connection_name = UP_AUTH)
|
98
99
|
raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
|
99
100
|
request_params = {
|
100
|
-
client_id: @client_id,
|
101
101
|
email: email,
|
102
|
+
password: password,
|
102
103
|
connection: connection_name,
|
103
|
-
|
104
|
+
client_id: @client_id
|
104
105
|
}
|
105
106
|
post('/dbconnections/change_password', request_params)
|
106
107
|
end
|
107
108
|
|
108
|
-
# Start
|
109
|
-
# @see https://auth0.com/docs/
|
110
|
-
# @
|
111
|
-
# @param
|
112
|
-
# @param
|
109
|
+
# Start Passwordless email login flow.
|
110
|
+
# @see https://auth0.com/docs/api/authentication#get-code-or-link
|
111
|
+
# @see https://auth0.com/docs/connections/passwordless#passwordless-on-regular-web-apps
|
112
|
+
# @param email [string] Email to send a link or code
|
113
|
+
# @param send [string] Pass 'link' to send a magic link, 'code' to send a code
|
114
|
+
# @param auth_params [hash] Append or override the magic link parameters
|
113
115
|
def start_passwordless_email_flow(email, send = 'link', auth_params = {})
|
114
116
|
raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
|
115
117
|
request_params = {
|
116
|
-
client_id: @client_id,
|
117
|
-
connection: 'email',
|
118
118
|
email: email,
|
119
119
|
send: send,
|
120
|
-
authParams: auth_params
|
120
|
+
authParams: auth_params,
|
121
|
+
connection: 'email',
|
122
|
+
client_id: @client_id
|
121
123
|
}
|
122
124
|
post('/passwordless/start', request_params)
|
123
125
|
end
|
124
126
|
|
125
|
-
# Start
|
126
|
-
# @see https://auth0.com/docs/
|
127
|
+
# Start Passwordless SMS login flow.
|
128
|
+
# @see https://auth0.com/docs/api/authentication#get-code-or-link
|
129
|
+
# @see https://auth0.com/docs/connections/passwordless#passwordless-on-regular-web-apps
|
127
130
|
# @param phone_number [string] User's phone number.
|
128
131
|
def start_passwordless_sms_flow(phone_number)
|
129
132
|
raise Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
|
130
133
|
request_params = {
|
131
|
-
|
134
|
+
phone_number: phone_number,
|
132
135
|
connection: 'sms',
|
133
|
-
|
136
|
+
client_id: @client_id
|
134
137
|
}
|
135
138
|
post('/passwordless/start', request_params)
|
136
139
|
end
|
137
140
|
|
138
|
-
#
|
139
|
-
# @see https://auth0.com/docs/
|
141
|
+
# Retrive SAML 2.0 metadata XML for an Application.
|
142
|
+
# @see https://auth0.com/docs/api/authentication#get-metadata
|
143
|
+
# @return [xml] SAML 2.0 metadata
|
144
|
+
def saml_metadata
|
145
|
+
get("/samlp/metadata/#{@client_id}")
|
146
|
+
end
|
147
|
+
|
148
|
+
# Retrieve WS-Federation metadata XML for a tenant.
|
149
|
+
# @see https://auth0.com/docs/api/authentication#get-metadata36
|
150
|
+
# @return [xml] WS-Federation metadata
|
151
|
+
def wsfed_metadata
|
152
|
+
get('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
|
153
|
+
end
|
154
|
+
|
155
|
+
# Return the user information based on the Auth0 access token.
|
156
|
+
# @see https://auth0.com/docs/api/authentication#get-user-info
|
157
|
+
# @return [json] User information based on the Auth0 access token
|
158
|
+
def user_info
|
159
|
+
get('/userinfo')
|
160
|
+
end
|
161
|
+
|
162
|
+
# Return an authorization URL.
|
163
|
+
# @see https://auth0.com/docs/api/authentication#authorization-code-grant
|
164
|
+
# @param redirect_uri [string] URL to redirect after authorization
|
165
|
+
# @param options [hash] Can contain response_type, connection, state and additional_parameters.
|
166
|
+
# @return [url] Authorization URL.
|
167
|
+
def authorization_url(redirect_uri, options = {})
|
168
|
+
raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
|
169
|
+
request_params = {
|
170
|
+
client_id: @client_id,
|
171
|
+
response_type: options.fetch(:response_type, 'code'),
|
172
|
+
connection: options.fetch(:connection, nil),
|
173
|
+
redirect_uri: redirect_uri,
|
174
|
+
state: options.fetch(:state, nil),
|
175
|
+
scope: options.fetch(:scope, nil)
|
176
|
+
}.merge(options.fetch(:additional_parameters, {}))
|
177
|
+
|
178
|
+
URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params))
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns an Auth0 logout URL with a return URL.
|
182
|
+
# @see https://auth0.com/docs/api/authentication#logout
|
183
|
+
# @see https://auth0.com/docs/logout
|
184
|
+
# @param return_to [string] URL to redirect after logout.
|
185
|
+
# @param include_client [bool] Include the client_id in the logout URL.
|
186
|
+
# @param federated [boolean] Perform a federated logout.
|
187
|
+
# @return [url] Logout URI
|
188
|
+
def logout_url(return_to, include_client: false, federated: false)
|
189
|
+
request_params = {
|
190
|
+
returnTo: return_to,
|
191
|
+
client_id: include_client ? @client_id : nil,
|
192
|
+
federated: federated ? '1' : nil
|
193
|
+
}
|
194
|
+
|
195
|
+
URI::HTTPS.build(
|
196
|
+
host: @domain,
|
197
|
+
path: '/v2/logout',
|
198
|
+
query: to_query(request_params)
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Return a SAMLP URL.
|
203
|
+
# The SAML Request AssertionConsumerServiceURL will be used to POST back
|
204
|
+
# the assertion and it must match with the application callback URL.
|
205
|
+
# @see https://auth0.com/docs/api/authentication#accept-request
|
206
|
+
# @param connection [string] Connection to use; empty to show all
|
207
|
+
# @return [url] SAMLP URL
|
208
|
+
def samlp_url(connection = UP_AUTH)
|
209
|
+
request_params = {
|
210
|
+
connection: connection
|
211
|
+
}
|
212
|
+
URI::HTTPS.build(host: @domain, path: "/samlp/#{@client_id}", query: to_query(request_params))
|
213
|
+
end
|
214
|
+
|
215
|
+
# Return a WS-Federation URL.
|
216
|
+
# @see https://auth0.com/docs/api/authentication#accept-request35
|
217
|
+
# @param connection [string] Connection to use; empty to show all
|
218
|
+
# @param options [hash] Extra options; supports wtrealm, wctx, wreply
|
219
|
+
# @return [url] WS-Federation URL
|
220
|
+
def wsfed_url(connection = UP_AUTH, options = {})
|
221
|
+
request_params = {
|
222
|
+
whr: connection,
|
223
|
+
wtrealm: options[:wtrealm],
|
224
|
+
wctx: options[:wctx],
|
225
|
+
wreply: options[:wreply]
|
226
|
+
}
|
227
|
+
|
228
|
+
url_client_id = @client_id if !request_params[:wtrealm]
|
229
|
+
URI::HTTPS.build(
|
230
|
+
host: @domain,
|
231
|
+
path: "/wsfed/#{url_client_id}",
|
232
|
+
query: to_query(request_params)
|
233
|
+
)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Login using phone number + verification code.
|
237
|
+
# @deprecated 4.5.0 - Legacy authentication pipeline; use a Password Grant
|
238
|
+
# instead - https://auth0.com/docs/api-auth/tutorials/password-grant
|
239
|
+
# @see https://auth0.com/docs/api/authentication#resource-owner
|
140
240
|
# @param phone_number [string] User's phone number.
|
141
241
|
# @param code [string] Verification code.
|
142
242
|
# @return [json] Returns the access token and id token
|
@@ -154,23 +254,10 @@ module Auth0
|
|
154
254
|
post('/oauth/ro', request_params)
|
155
255
|
end
|
156
256
|
|
157
|
-
#
|
158
|
-
# @
|
159
|
-
# @
|
160
|
-
|
161
|
-
get("/samlp/metadata/#{@client_id}")
|
162
|
-
end
|
163
|
-
|
164
|
-
# Retrives the WS-Federation metadata
|
165
|
-
# @see https://auth0.com/docs/auth-api#!#get--wsfed--client_id-
|
166
|
-
# @return [xml] Federation Metadata
|
167
|
-
def wsfed_metadata
|
168
|
-
get('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
|
169
|
-
end
|
170
|
-
|
171
|
-
# Validates a JSON Web Token (signature and expiration)
|
172
|
-
# @see https://auth0.com/docs/auth-api#!#post--tokeninfo
|
173
|
-
# @param id_token [string] Token's id.
|
257
|
+
# Validate a JSON Web Token (signature and expiration).
|
258
|
+
# @deprecated 4.5.0 - Legacy endpoint, use /userinfo instead.
|
259
|
+
# @see https://auth0.com/docs/api/authentication#get-token-info
|
260
|
+
# @param id_token [string] ID Token to use
|
174
261
|
# @return User information associated with the user id (sub property) of the token.
|
175
262
|
def token_info(id_token)
|
176
263
|
raise Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
|
@@ -178,8 +265,10 @@ module Auth0
|
|
178
265
|
post('/tokeninfo', request_params)
|
179
266
|
end
|
180
267
|
|
181
|
-
#
|
182
|
-
# @
|
268
|
+
# Refresh a delegation token.
|
269
|
+
# @deprecated 4.5.0 - Feature is disabled, no replacement currently; see
|
270
|
+
# https://auth0.com/docs/api-auth/tutorials/adoption/delegation
|
271
|
+
# @see https://auth0.com/docs/api/authentication#delegation
|
183
272
|
# @param refresh_token [string] Token to refresh
|
184
273
|
# @param target [string] Target to sign the new token.
|
185
274
|
# @param scope [string] Defaults to openid. Can be 'openid name email'.
|
@@ -200,8 +289,10 @@ module Auth0
|
|
200
289
|
post('/delegation', request_params)
|
201
290
|
end
|
202
291
|
|
203
|
-
#
|
204
|
-
# @
|
292
|
+
# Retrieve a delegation token.
|
293
|
+
# @deprecated 4.5.0 - Feature is disabled, no replacement currently; see
|
294
|
+
# https://auth0.com/docs/api-auth/tutorials/adoption/delegation
|
295
|
+
# @see https://auth0.com/docs/api/authentication#delegation
|
205
296
|
# @param id_token [string] Token's id.
|
206
297
|
# @param target [string] Target to sign the new token.
|
207
298
|
# @param scope [string] Defaults to openid. Can be 'openid name email'.
|
@@ -222,8 +313,9 @@ module Auth0
|
|
222
313
|
post('/delegation', request_params)
|
223
314
|
end
|
224
315
|
|
225
|
-
#
|
226
|
-
# @
|
316
|
+
# Retrieve an impersonation URL to login as another user.
|
317
|
+
# @deprecated 4.5.0 - Feature is disabled.
|
318
|
+
# @see https://auth0.com/docs/api/authentication#impersonation
|
227
319
|
# @param user_id [string] Impersonate user id
|
228
320
|
# @param app_client_id [string] Application client id
|
229
321
|
# @param impersonator_id [string] Impersonator user id id.
|
@@ -251,9 +343,12 @@ module Auth0
|
|
251
343
|
authorization_header @token
|
252
344
|
result
|
253
345
|
end
|
346
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
254
347
|
|
255
|
-
#
|
256
|
-
# @
|
348
|
+
# Unlink a user's account from the identity provider.
|
349
|
+
# @deprecated 4.5.0 - Endpoint is disabled in favor of the Management API;
|
350
|
+
# see https://auth0.com/docs/migrations/guides/account-linking
|
351
|
+
# @see https://auth0.com/docs/api/authentication#unlink
|
257
352
|
# @param access_token [string] Logged-in user access token
|
258
353
|
# @param user_id [string] User Id
|
259
354
|
def unlink_user(access_token, user_id)
|
@@ -266,72 +361,13 @@ module Auth0
|
|
266
361
|
post('/unlink', request_params)
|
267
362
|
end
|
268
363
|
|
269
|
-
# Returns the user information based on the Auth0 access token.
|
270
|
-
# @see https://auth0.com/docs/auth-api#!#get--userinfo
|
271
|
-
# @return [json] User information based on the Auth0 access token
|
272
|
-
def user_info
|
273
|
-
get('/userinfo')
|
274
|
-
end
|
275
|
-
|
276
|
-
# Returns an authorization URL, triggers a redirect.
|
277
|
-
# @see https://auth0.com/docs/auth-api#!#get--authorize_social
|
278
|
-
# @param redirect_uri [string] Url to redirect after authorization
|
279
|
-
# @param options [hash] Can contain response_type, connection, state and additional_parameters.
|
280
|
-
# @return [url] Authorization URL.
|
281
|
-
def authorization_url(redirect_uri, options = {})
|
282
|
-
raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
|
283
|
-
request_params = {
|
284
|
-
client_id: @client_id,
|
285
|
-
response_type: options.fetch(:response_type, 'code'),
|
286
|
-
connection: options.fetch(:connection, nil),
|
287
|
-
redirect_uri: redirect_uri,
|
288
|
-
state: options.fetch(:state, nil),
|
289
|
-
scope: options.fetch(:scope, nil)
|
290
|
-
}.merge(options.fetch(:additional_parameters, {}))
|
291
|
-
|
292
|
-
URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params))
|
293
|
-
end
|
294
|
-
|
295
|
-
# Returns an logout URL, triggers the logout flow.
|
296
|
-
# @see https://auth0.com/docs/auth-api#!#get--logout
|
297
|
-
# @param return_to [string] Url to redirect after authorization
|
298
|
-
# @return [url] Logout URL.
|
299
|
-
def logout_url(return_to)
|
300
|
-
request_params = {
|
301
|
-
returnTo: return_to
|
302
|
-
}
|
303
|
-
|
304
|
-
URI::HTTPS.build(host: @domain, path: '/logout', query: to_query(request_params))
|
305
|
-
end
|
306
|
-
|
307
|
-
# Returns a samlp URL. The SAML Request AssertionConsumerServiceURL will be used to POST back the assertion
|
308
|
-
# and it has to match with the application callback URL.
|
309
|
-
# @see https://auth0.com/docs/auth-api#get--samlp--client_id-
|
310
|
-
# @param connection [string] to login with a specific provider.
|
311
|
-
# @return [url] samlp URL.
|
312
|
-
def samlp_url(connection = UP_AUTH)
|
313
|
-
request_params = {
|
314
|
-
connection: connection
|
315
|
-
}
|
316
|
-
URI::HTTPS.build(host: @domain, path: "/samlp/#{@client_id}", query: to_query(request_params))
|
317
|
-
end
|
318
|
-
|
319
|
-
# Returns a wsfed URL.
|
320
|
-
# @see https://auth0.com/docs/auth-api#get--wsfed--client_id-
|
321
|
-
# @param connection [string] to login with a specific provider.
|
322
|
-
# @return [url] wsfed URL.
|
323
|
-
def wsfed_url(connection = UP_AUTH)
|
324
|
-
request_params = {
|
325
|
-
whr: connection
|
326
|
-
}
|
327
|
-
URI::HTTPS.build(host: @domain, path: "/wsfed/#{@client_id}", query: to_query(request_params))
|
328
|
-
end
|
329
|
-
|
330
364
|
private
|
331
365
|
|
366
|
+
# Build a URL query string from a hash.
|
332
367
|
def to_query(hash)
|
333
|
-
hash.map { |k, v| "#{k}=#{
|
368
|
+
hash.map { |k, v| "#{k}=#{CGI.escape(v)}" unless v.nil? }.reject(&:nil?).join('&')
|
334
369
|
end
|
335
370
|
end
|
336
371
|
end
|
337
372
|
end
|
373
|
+
# rubocop:enable Metrics/ModuleLength
|