slack-api-wrapper 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,81 +0,0 @@
1
- # Copyright (c) 2015 Gustavo Bazan
2
- # MIT License
3
-
4
- require 'uri'
5
-
6
- module Slack
7
- module Oauth2
8
- # Base class for the OAuth 2 authorization helpers.
9
- class FlowBase
10
- def initialize(consumer_key, consumer_secret, scope, team)
11
- unless consumer_key.is_a?(String)
12
- raise ArgumentError, "consumer_key must be a String, got #{consumer_key.inspect}"
13
- end
14
- unless consumer_secret.is_a?(String)
15
- raise ArgumentError, "consumer_secret must be a String, got #{consumer_secret.inspect}"
16
- end
17
- unless scope.is_a?(String)
18
- raise ArgumentError, "scope must be a String, got #{scope.inspect}"
19
- end
20
-
21
- @consumer_key = consumer_key
22
- @consumer_secret = consumer_secret
23
- @scope = scope
24
- @team = team
25
- end
26
-
27
- protected
28
-
29
- def _get_authorize_url(redirect_uri, state)
30
- params = {
31
- "client_id" => @consumer_key,
32
- "redirect_uri" => redirect_uri,
33
- "scope" => @scope,
34
- "state" => state,
35
- "team" => @team
36
- }
37
-
38
- host = Slack::WEB_SERVER
39
- path = "/oauth/authorize"
40
-
41
- target = URI::Generic.new("https", nil, host, nil, nil, path, nil, nil, nil)
42
- target.query = Slack::make_query_string(params)
43
-
44
- target.to_s
45
- end
46
-
47
- # Finish the OAuth 2 authorization process. If you used a redirect_uri, pass that in.
48
- # Will return an access token string that you can use with SlackClient.
49
- def _finish(code, original_redirect_uri)
50
-
51
- raise ArgumentError, "code must be a String" unless code.is_a?(String)
52
-
53
- uri = URI.parse("https://#{Slack::API_SERVER}/oauth.access")
54
- request = Net::HTTP::Post.new(uri.request_uri)
55
-
56
- params = {
57
- "client_id" => @consumer_key,
58
- "client_secret" => @consumer_secret,
59
- "code" => code,
60
- "redirect_uri" => original_redirect_uri
61
- }
62
-
63
- request.set_form_data(Slack::clean_params(params))
64
-
65
- response = Slack::do_http(uri, request)
66
-
67
- j = Slack::parse_response(response)
68
- ["access_token", "scope"].each do |k|
69
- unless j.has_key?(k)
70
- raise Slack::Error.new("Bad response from /token: missing \"#{k}\".")
71
- end
72
- unless j[k].is_a?(String)
73
- raise Slack::Error.new("Bad response from /token: field \"#{k}\" is not a string.")
74
- end
75
- end
76
-
77
- return j['access_token'], j['scope']
78
- end
79
- end
80
- end
81
- end
File without changes
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Slack::Oauth2 do
4
- it 'do something' do
5
- skip
6
- end
7
- end