Class: SlackWebApi::AuthorizationCodeAuthCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_web_api/http/auth/oauth_2.rb

Overview

Data class for AuthorizationCodeAuthCredentials.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_client_id:, oauth_client_secret:, oauth_redirect_uri:, oauth_token: nil, oauth_scopes: nil) ⇒ AuthorizationCodeAuthCredentials

Returns a new instance of AuthorizationCodeAuthCredentials.

Raises:

  • (ArgumentError)


116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 116

def initialize(oauth_client_id:, oauth_client_secret:, oauth_redirect_uri:,
               oauth_token: nil, oauth_scopes: nil)
  raise ArgumentError, 'oauth_client_id cannot be nil' if oauth_client_id.nil?
  raise ArgumentError, 'oauth_client_secret cannot be nil' if oauth_client_secret.nil?
  raise ArgumentError, 'oauth_redirect_uri cannot be nil' if oauth_redirect_uri.nil?

  @oauth_client_id = oauth_client_id
  @oauth_client_secret = oauth_client_secret
  @oauth_redirect_uri = oauth_redirect_uri
  @oauth_token = oauth_token
  @oauth_scopes = oauth_scopes
end

Instance Attribute Details

#oauth_client_idObject (readonly)

Returns the value of attribute oauth_client_id.



113
114
115
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 113

def oauth_client_id
  @oauth_client_id
end

#oauth_client_secretObject (readonly)

Returns the value of attribute oauth_client_secret.



113
114
115
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 113

def oauth_client_secret
  @oauth_client_secret
end

#oauth_redirect_uriObject (readonly)

Returns the value of attribute oauth_redirect_uri.



113
114
115
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 113

def oauth_redirect_uri
  @oauth_redirect_uri
end

#oauth_scopesObject (readonly)

Returns the value of attribute oauth_scopes.



113
114
115
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 113

def oauth_scopes
  @oauth_scopes
end

#oauth_tokenObject (readonly)

Returns the value of attribute oauth_token.



113
114
115
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 113

def oauth_token
  @oauth_token
end

Class Method Details

.from_envObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 129

def self.from_env
  oauth_client_id = ENV['OAUTH_CLIENT_ID']
  oauth_client_secret = ENV['OAUTH_CLIENT_SECRET']
  oauth_redirect_uri = ENV['OAUTH_REDIRECT_URI']
  oauth_scopes = ENV['OAUTH_SCOPES']
  all_nil = [
    oauth_client_id,
    oauth_client_secret,
    oauth_redirect_uri
  ].all?(&:nil?)
  return nil if all_nil

  new(oauth_client_id: oauth_client_id,
      oauth_client_secret: oauth_client_secret,
      oauth_redirect_uri: oauth_redirect_uri, oauth_scopes: oauth_scopes)
end

Instance Method Details

#clone_with(oauth_client_id: nil, oauth_client_secret: nil, oauth_redirect_uri: nil, oauth_token: nil, oauth_scopes: nil) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/slack_web_api/http/auth/oauth_2.rb', line 146

def clone_with(oauth_client_id: nil, oauth_client_secret: nil,
               oauth_redirect_uri: nil, oauth_token: nil, oauth_scopes: nil)
  oauth_client_id ||= self.oauth_client_id
  oauth_client_secret ||= self.oauth_client_secret
  oauth_redirect_uri ||= self.oauth_redirect_uri
  oauth_token ||= self.oauth_token
  oauth_scopes ||= self.oauth_scopes

  AuthorizationCodeAuthCredentials.new(
    oauth_client_id: oauth_client_id,
    oauth_client_secret: oauth_client_secret,
    oauth_redirect_uri: oauth_redirect_uri, oauth_token: oauth_token,
    oauth_scopes: oauth_scopes
  )
end