auth-service-authenticator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/lib/auth/service/authenticator.rb +21 -0
- data/lib/auth/service/authenticator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2702ae80932f8f388287ae9b03d37c349505887
|
4
|
+
data.tar.gz: c773ed43fc21eeba4afa9466464a70d99c7b919e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b50d1943abff5150179a67add60bf35873a148fc17a7c1bf8d80b3bd16cebd505574fbb9b8ebe47b1d5dfe67a51eb5c0a0553914e2001bc5802704e0c619fbc
|
7
|
+
data.tar.gz: 8c24ceca0ec451e58f1d4a4ecb761abdcfd209b66e91b98291cbf1532dd6798f6a85d12423ced277122fca83b56158c0ab335e030111eb976c2f1c56880832ce
|
data/README.md
CHANGED
@@ -11,13 +11,20 @@ Adicione essa linha ao seu Gemfile:
|
|
11
11
|
gem 'auth-service-authenticator'
|
12
12
|
```
|
13
13
|
|
14
|
-
|
14
|
+
na pasta `config` crie um arquivo com o nome `authenticator_config.yml` e adicione as chaves:
|
15
|
+
```ruby
|
16
|
+
url: URL_DO_SERVICO_DE_AUTENTICACAO
|
17
|
+
port: PORTA_DO_SERVICE_DE_AUTENTICACAO
|
18
|
+
```
|
15
19
|
|
16
|
-
|
20
|
+
Agora execute:
|
21
|
+
```sh
|
22
|
+
$ bundle install
|
23
|
+
```
|
17
24
|
|
18
25
|
## Como Utilizar
|
19
26
|
|
20
|
-
Utilize os metodos `authenticate` e `validate_token`:
|
27
|
+
Utilize os metodos `authenticate` e `validate_token` e `logout`:
|
21
28
|
```ruby
|
22
29
|
# Autentique o usuário fonecendo o email e senha
|
23
30
|
response = Auth::Service::Authenticator::Manager.authenticate('EMAIL', 'SENHA')
|
@@ -63,6 +70,9 @@ Utilize os metodos `authenticate` e `validate_token`:
|
|
63
70
|
|
64
71
|
# Caso o token seja válido, continue com sua aplicação normalmente.
|
65
72
|
# Caso inválido, redirecione o usuário para página de login.
|
73
|
+
|
74
|
+
# Logout do usuário
|
75
|
+
response = Auth::Service::Authenticator::Manager.logout('TOKEN')
|
66
76
|
```
|
67
77
|
|
68
78
|
## Development
|
@@ -56,6 +56,27 @@ module Auth
|
|
56
56
|
return result
|
57
57
|
end
|
58
58
|
|
59
|
+
def self.logout(token)
|
60
|
+
uri = URI.parse("#{@@auth_url}")
|
61
|
+
http = Net::HTTP.new(@@auth_url, @@auth_port)
|
62
|
+
request = Net::HTTP::Delete.new("/api/v1/authenticate")
|
63
|
+
request.add_field('Content-Type', 'application/json')
|
64
|
+
request.add_field('Authorization', token)
|
65
|
+
response = http.request(request)
|
66
|
+
|
67
|
+
result = case response
|
68
|
+
when Net::HTTPNoContent then
|
69
|
+
{ status: response.code, message: 'success', success: true }
|
70
|
+
when Net::HTTPClientError then
|
71
|
+
{ error: 'Token invalido.', status: response.code, message: response.message }
|
72
|
+
when Net::ReadTimeout then
|
73
|
+
{ error: 'timeout', status: response.code, message: response.message }
|
74
|
+
else
|
75
|
+
{ error: 'erro inesperado. tente novamente mais tarde.', status: '422', message: '' }
|
76
|
+
end
|
77
|
+
return result
|
78
|
+
end
|
79
|
+
|
59
80
|
private
|
60
81
|
# Setup auth server configuration
|
61
82
|
def self.configure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth-service-authenticator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Paulino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|