haveapi-go-client 0.19.3 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e280d2ae1a1a0bad8fb3436d97493f3b15f6accb65e919af2fa7cb0fc751108f
4
- data.tar.gz: 21f2f8bdf6ddf4f0d28e994fabbc865be6a0cce7fc1a9f67c868a02ab2d8427f
3
+ metadata.gz: db88d2729b86152d843b5714fe2e55dcf5eb33382b6d50196eb3c04a5c7549b4
4
+ data.tar.gz: 7505c745f672b7d2aa09f5ccc38aaa70c34dfc86a68b59bf732d5aab22f440e3
5
5
  SHA512:
6
- metadata.gz: 8b520855fe4036001908341c247bf9b71b6868ba91fdbba5dab188b45f479be40bd1dbe12825ee2499d8d1e84ca2d3064ca6e5fe8b70111b6490288662a6a7b4
7
- data.tar.gz: 570f73252a60726a109e3c23bddbc5f09aa3f2543f9706d8db4a901e96ea7fa87bccbaf4dd13aa713bc695b795097137f1fb6452255354e06f89b808e3b897db
6
+ metadata.gz: c7680dd117b5ee738e72f66f6652ffeca053da2904173a924667ecd51789be4cde6c7821182698de0f26365e8d816813175d842a3fa72e845d9466589fa6d0d9
7
+ data.tar.gz: 9f56f3b3e8b470a3ca87df671a0ac18c0bc87b852c7bfc9d377d689680f51cea92d1b7ecc0bbd43f0a63632b481f647466594574be7c8ce9256dcad249698a00
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake'
23
23
 
24
- spec.add_runtime_dependency 'haveapi-client', '~> 0.19.3'
24
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.20.0'
25
25
  end
@@ -0,0 +1,31 @@
1
+ require 'haveapi/go_client/authentication/base'
2
+
3
+ module HaveAPI::GoClient
4
+ class Authentication::OAuth2 < Authentication::Base
5
+ register :oauth2
6
+
7
+ # HTTP header the token is sent in
8
+ # @return [String]
9
+ attr_reader :http_header
10
+
11
+ # Token revocation URL
12
+ # @return [String]
13
+ attr_reader :revoke_url
14
+
15
+ def initialize(api_version, name, desc)
16
+ @http_header = desc[:http_header]
17
+ @revoke_url = desc[:revoke_url]
18
+ end
19
+
20
+ def generate(gen)
21
+ ErbTemplate.render_to_if_changed(
22
+ 'authentication/oauth2.go',
23
+ {
24
+ package: gen.package,
25
+ auth: self,
26
+ },
27
+ File.join(gen.dst, 'auth_oauth2.go')
28
+ )
29
+ end
30
+ end
31
+ end
@@ -26,7 +26,7 @@ module HaveAPI::GoClient
26
26
  end
27
27
 
28
28
  def initialize(name, vars)
29
- @_tpl = ERB.new(File.new(HaveAPI::GoClient.tpl(name)).read, 0, '-')
29
+ @_tpl = ERB.new(File.new(HaveAPI::GoClient.tpl(name)).read, trim_mode: '-')
30
30
 
31
31
  vars.each do |k, v|
32
32
  if v.is_a?(Proc)
@@ -1,5 +1,5 @@
1
1
  module HaveAPI
2
2
  module GoClient
3
- VERSION = '0.19.3'
3
+ VERSION = '0.20.0'
4
4
  end
5
5
  end
@@ -0,0 +1,53 @@
1
+ package <%= package %>
2
+
3
+ import (
4
+ "fmt"
5
+ "net/http"
6
+ )
7
+
8
+ type OAuth2Auth struct {
9
+ // The authentication token
10
+ AccessToken string
11
+ }
12
+
13
+ func (auth *OAuth2Auth) Authenticate(request *http.Request) {
14
+ request.Header.Set("<%= auth.http_header %>", auth.AccessToken)
15
+ }
16
+
17
+ // SetExistingTokenAuth will use a previously acquired access token
18
+ func (client *Client) SetExistingOAuth2Auth(accessToken string) {
19
+ client.Authentication = &OAuth2Auth{
20
+ AccessToken: accessToken,
21
+ }
22
+ }
23
+
24
+ // RevokeAuthToken will revoke the access token and remove authentication
25
+ // from the client
26
+ func (client *Client) RevokeAccessToken() error {
27
+ httpClient := &http.Client{}
28
+
29
+ req, err := http.NewRequest("POST", "<%= auth.revoke_url %>", nil)
30
+
31
+ if err != nil {
32
+ return err
33
+ }
34
+
35
+ if client.Authentication != nil {
36
+ client.Authentication.Authenticate(req)
37
+ }
38
+
39
+ resp, err := httpClient.Do(req)
40
+
41
+ if err != nil {
42
+ return err
43
+ }
44
+
45
+ defer resp.Body.Close()
46
+
47
+ if resp.StatusCode != 200 {
48
+ return fmt.Errorf("Unable to revoke access token, HTTP %v", resp.StatusCode)
49
+ }
50
+
51
+ client.Authentication = nil
52
+ return nil
53
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-go-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.3
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.19.3
47
+ version: 0.20.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.19.3
54
+ version: 0.20.0
55
55
  description: Go client generator
56
56
  email:
57
57
  - jakub.skokan@vpsfree.cz
@@ -71,6 +71,7 @@ files:
71
71
  - lib/haveapi/go_client/api_version.rb
72
72
  - lib/haveapi/go_client/authentication/base.rb
73
73
  - lib/haveapi/go_client/authentication/basic.rb
74
+ - lib/haveapi/go_client/authentication/oauth2.rb
74
75
  - lib/haveapi/go_client/authentication/token.rb
75
76
  - lib/haveapi/go_client/authentication/unsupported.rb
76
77
  - lib/haveapi/go_client/authentication_methods.rb
@@ -92,6 +93,7 @@ files:
92
93
  - template/action.go.erb
93
94
  - template/authentication.go.erb
94
95
  - template/authentication/basic.go.erb
96
+ - template/authentication/oauth2.go.erb
95
97
  - template/authentication/token.go.erb
96
98
  - template/client.go.erb
97
99
  - template/go.mod.erb