Module: Auth0::Api::AuthenticationEndpoints
- Defined in:
- lib/auth0/api/authentication_endpoints.rb
Overview
https://auth0.com/docs/auth-api Methods to use the authentication endpoints
Constant Summary collapse
- UP_AUTH =
'Username-Password-Authentication'- JWT_BEARER =
'urn:ietf:params:oauth:grant-type:jwt-bearer'
Instance Method Summary collapse
-
#authorization_url(redirect_uri, options = {}) ⇒ url
Returns an authorization URL, triggers a redirect.
-
#change_password(email, password, connection_name = UP_AUTH) ⇒ Object
Asks to change a password for a given user.
-
#delegation(id_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) ⇒ json
Retrives a delegation token.
-
#impersonate(user_id, app_client_id, impersonator_id, options) ⇒ string
Retrives an impersonation URL to login as another user.
-
#login(username, password, id_token = nil, connection_name = UP_AUTH, options = {}) ⇒ json
Logins using username/password Active Directory/LDAP, Windows Azure AD and ADF.
-
#logout_url(return_to) ⇒ url
Returns an logout URL, triggers the logout flow.
-
#obtain_access_token(access_token = nil, connection = 'facebook', scope = 'openid') ⇒ json
Retrives an access token.
-
#phone_login(phone_number, code, scope = 'openid') ⇒ json
Logins using phone number/verification code.
-
#refresh_delegation(refresh_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) ⇒ json
Refreshes a delegation token.
-
#saml_metadata(client_id) ⇒ xml
Retrives the SAML 2.0 metadata.
-
#samlp_url(connection = UP_AUTH) ⇒ url
Returns a samlp URL.
-
#signup(email, password, connection_name = UP_AUTH) ⇒ json
Signup using username/password.
-
#start_passwordless_email_flow(email, send = 'link', auth_params = {}) ⇒ Object
Start passwordless workflow sending an email.
-
#start_passwordless_sms_flow(phone_number) ⇒ Object
Start passwordless workflow sending a SMS message.
-
#token_info(id_token) ⇒ Object
Validates a JSON Web Token (signature and expiration).
-
#unlink_user(access_token, user_id) ⇒ Object
Unlinks a User.
-
#user_info ⇒ json
Returns the user information based on the Auth0 access token.
-
#wsfed_metadata ⇒ xml
Retrives the WS-Federation metadata.
-
#wsfed_url(connection = UP_AUTH) ⇒ url
Returns a wsfed URL.
Instance Method Details
#authorization_url(redirect_uri, options = {}) ⇒ url
Returns an authorization URL, triggers a redirect.
252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 252 def (redirect_uri, = {}) fail Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty? request_params = { client_id: @client_id, response_type: .fetch(:connection, 'code'), connection: .fetch(:connection, nil), redirect_url: redirect_uri, state: .fetch(:state, nil) }.merge(.fetch(:additional_parameters, {})) URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params)) end |
#change_password(email, password, connection_name = UP_AUTH) ⇒ Object
Asks to change a password for a given user. Send an email to the user.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 74 def change_password(email, password, connection_name = UP_AUTH) fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty? request_params = { client_id: @client_id, email: email, connection: connection_name, password: password } post('/dbconnections/change_password', request_params) end |
#delegation(id_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) ⇒ json
Retrives a delegation token
190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 190 def delegation(id_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) fail Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty? request_params = { client_id: @client_id, grant_type: JWT_BEARER, id_token: id_token, target: target, api_type: api_type, scope: scope }.merge(extra_parameters) post('/delegation', request_params) end |
#impersonate(user_id, app_client_id, impersonator_id, options) ⇒ string
Retrives an impersonation URL to login as another user
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 210 def impersonate(user_id, app_client_id, impersonator_id, ) fail Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty? request_params = { protocol: .fetch(:protocol, 'oauth2'), impersonator_id: impersonator_id, client_id: app_client_id, additionalParameters: { response_type: .fetch(:response_type, 'code'), state: .fetch(:state, ''), scope: .fetch(:scope, 'openid'), callback_url: .fetch(:callback_url, '') } } post("/users/#{user_id}/impersonate", request_params) end |
#login(username, password, id_token = nil, connection_name = UP_AUTH, options = {}) ⇒ json
Logins using username/password Active Directory/LDAP, Windows Azure AD and ADF
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 34 def login(username, password, id_token = nil, connection_name = UP_AUTH, = {}) fail Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty? fail Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty? request_params = { client_id: @client_id, username: username, password: password, scope: .fetch(:scope, 'openid'), connection: connection_name, grant_type: .fetch(:grant_type, password), id_token: id_token, device: .fetch(:device, nil) } post('/oauth/ro', request_params) end |
#logout_url(return_to) ⇒ url
Returns an logout URL, triggers the logout flow.
269 270 271 272 273 274 275 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 269 def logout_url(return_to) request_params = { returnTo: return_to } URI::HTTPS.build(host: @domain, path: '/logout', query: to_query(request_params)) end |
#obtain_access_token(access_token = nil, connection = 'facebook', scope = 'openid') ⇒ json
Retrives an access token
15 16 17 18 19 20 21 22 23 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 15 def obtain_access_token(access_token = nil, connection = 'facebook', scope = 'openid') if access_token request_params = { client_id: @client_id, access_token: access_token, connection: connection, scope: scope } post('/oauth/access_token', request_params)['access_token'] else request_params = { client_id: @client_id, client_secret: @client_secret, grant_type: 'client_credentials' } post('/oauth/token', request_params)['access_token'] end end |
#phone_login(phone_number, code, scope = 'openid') ⇒ json
Logins using phone number/verification code.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 119 def phone_login(phone_number, code, scope = 'openid') fail Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty? fail Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty? request_params = { client_id: @client_id, username: phone_number, password: code, scope: scope, connection: 'sms', grant_type: 'password' } post('/oauth/ro', request_params) end |
#refresh_delegation(refresh_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) ⇒ json
Refreshes a delegation token
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 168 def refresh_delegation(refresh_token, target, scope = 'openid', api_type = 'app', extra_parameters = {}) fail Auth0::InvalidParameter, 'Must supply a valid token to refresh' if refresh_token.to_s.empty? request_params = { client_id: @client_id, grant_type: JWT_BEARER, refresh_token: refresh_token, target: target, api_type: api_type, scope: scope }.merge(extra_parameters) post('/delegation', request_params) end |
#saml_metadata(client_id) ⇒ xml
Retrives the SAML 2.0 metadata
137 138 139 140 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 137 def (client_id) fail Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty? get("/samlp/metadata/#{client_id}") end |
#samlp_url(connection = UP_AUTH) ⇒ url
Returns a samlp URL. The SAML Request AssertionConsumerServiceURL will be used to POST back the assertion and it has to match with the application callback URL.
282 283 284 285 286 287 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 282 def samlp_url(connection = UP_AUTH) request_params = { connection: connection } URI::HTTPS.build(host: @domain, path: "/samlp/#{@client_id}", query: to_query(request_params)) end |
#signup(email, password, connection_name = UP_AUTH) ⇒ json
Signup using username/password
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 56 def signup(email, password, connection_name = UP_AUTH) fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty? fail Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty? request_params = { client_id: @client_id, email: email, connection: connection_name, password: password } post('/dbconnections/signup', request_params) end |
#start_passwordless_email_flow(email, send = 'link', auth_params = {}) ⇒ Object
Start passwordless workflow sending an email
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 90 def start_passwordless_email_flow(email, send = 'link', auth_params = {}) fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty? request_params = { client_id: @client_id, email: email, send: send, auth_params: auth_params } post('/passwordless/start', request_params) end |
#start_passwordless_sms_flow(phone_number) ⇒ Object
Start passwordless workflow sending a SMS message
104 105 106 107 108 109 110 111 112 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 104 def start_passwordless_sms_flow(phone_number) fail Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty? request_params = { client_id: @client_id, connection: 'sms', phone_number: phone_number } post('/passwordless/start', request_params) end |
#token_info(id_token) ⇒ Object
Validates a JSON Web Token (signature and expiration)
153 154 155 156 157 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 153 def token_info(id_token) fail Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty? request_params = { id_token: id_token } post('/tokeninfo', request_params) end |
#unlink_user(access_token, user_id) ⇒ Object
Unlinks a User
230 231 232 233 234 235 236 237 238 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 230 def unlink_user(access_token, user_id) fail Auth0::InvalidParameter, 'Must supply a valid access_token' if access_token.to_s.empty? fail Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty? request_params = { access_token: access_token, user_id: user_id } post('/unlink', request_params) end |
#user_info ⇒ json
Returns the user information based on the Auth0 access token.
243 244 245 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 243 def user_info get('/userinfo') end |
#wsfed_metadata ⇒ xml
Retrives the WS-Federation metadata
145 146 147 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 145 def get('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml') end |
#wsfed_url(connection = UP_AUTH) ⇒ url
Returns a wsfed URL.
293 294 295 296 297 298 |
# File 'lib/auth0/api/authentication_endpoints.rb', line 293 def wsfed_url(connection = UP_AUTH) request_params = { whr: connection } URI::HTTPS.build(host: @domain, path: "/wsfed/#{@client_id}", query: to_query(request_params)) end |