Module: OpenTox::Authorization
- Defined in:
- lib/aa.rb
Class Method Summary collapse
-
.authenticate(user, pw) ⇒ Boolean
Authentication against OpenSSO.
-
.is_token_valid(subjectid = RestClientWrapper.subjectid) ⇒ Boolean
Checks if a token is a valid token.
-
.logout(subjectid = RestClientWrapper.subjectid) ⇒ Boolean
Logout on opensso.
Class Method Details
.authenticate(user, pw) ⇒ Boolean
Authentication against OpenSSO. Returns token. Requires Username and Password.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aa.rb', line 43 def self.authenticate(user, pw) begin res = RestClientWrapper.post("#{AA}/auth/authenticate",{:username=>user, :password => pw},{:subjectid => ""}).sub("token.id=","").sub("\n","") if is_token_valid(res) RestClientWrapper.subjectid = res return true else bad_request_error "Authentication failed #{res.inspect}" end rescue bad_request_error "Authentication failed #{res.inspect}" end end |
.is_token_valid(subjectid = RestClientWrapper.subjectid) ⇒ Boolean
Checks if a token is a valid token
73 74 75 76 77 78 79 80 |
# File 'lib/aa.rb', line 73 def self.is_token_valid(subjectid=RestClientWrapper.subjectid) begin return true if RestClientWrapper.post("#{AA}/auth/isTokenValid",:tokenid => subjectid) == "boolean=true\n" rescue #do rescue because openSSO throws 401 return false end return false end |
.logout(subjectid = RestClientWrapper.subjectid) ⇒ Boolean
Logout on opensso. Make token invalid. Requires token
60 61 62 63 64 65 66 67 68 |
# File 'lib/aa.rb', line 60 def self.logout(subjectid=RestClientWrapper.subjectid) begin out = RestClientWrapper.post("#{AA}/auth/logout", :subjectid => subjectid) return true unless is_token_valid(subjectid) rescue return false end return false end |