usos_auth_lib 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -34
- data/app/controllers/usos_auth_lib/usos_controller.rb +10 -13
- data/app/models/concerns/usos_auth_common.rb +25 -6
- data/lib/usos_auth_lib/version.rb +1 -1
- data/lib/usos_auth_lib.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eee3395c39abdb1728488402efdf0031fcf25e82fee6e2744298b7dd99a7ada3
|
|
4
|
+
data.tar.gz: 6a10256f1a17f26c1d2e865f0e531e6aafeeb4d3dd777a9c8bbeb70ac3daec09
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8c8a609c03eb87242389d6a561ae80e17f1403468b4c8f53fe3974c02a9114afd8802c456aac190db04a4086942ed02be797413659b68d5e79907ac4090c194
|
|
7
|
+
data.tar.gz: 40d5ff729c4e5f42c627a3380fa430776b159e0e72685e3694f91593a6a845c8669ce5569e46a6ee675f52adefe0bbc87017fb06110abb674a76603e1e41d844
|
data/README.md
CHANGED
|
@@ -6,6 +6,25 @@ The USOS API, a cornerstone of academic data access, opens up a world of possibi
|
|
|
6
6
|
|
|
7
7
|
The OAuth 1.0a workflow ensures a robust and secure authentication process, safeguarding user credentials while granting seamless access to the USOS API. By adhering to the guidelines provided in the official source, developers can confidently build applications that tap into the extensive educational resources offered by USOS, enriching their projects with academic data in a reliable and user-friendly manner. Explore the possibilities of educational integration through the USOS API and OAuth 1.0a, empowering your applications with a wealth of valuable information.
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "usos_auth_lib"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
```bash
|
|
19
|
+
$ bundle
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
```bash
|
|
24
|
+
$ gem install usos_auth_lib
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
|
|
9
28
|
## Usage
|
|
10
29
|
Here's an example for adding the configuration to a Rails app in `config/initializers/usos_auth_lib.rb`:
|
|
11
30
|
```ruby
|
|
@@ -45,7 +64,6 @@ class User < ApplicationRecord
|
|
|
45
64
|
first_name: token[:first_name],
|
|
46
65
|
last_name: token[:last_name],
|
|
47
66
|
usos_id: token[:id],
|
|
48
|
-
img_url: token[:photo_url] || nil
|
|
49
67
|
) unless user
|
|
50
68
|
|
|
51
69
|
user
|
|
@@ -55,33 +73,24 @@ end
|
|
|
55
73
|
|
|
56
74
|
Here's an example for callback method in `controllers/users_controller.rb`:
|
|
57
75
|
```ruby
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
session[:
|
|
61
|
-
session[:access_token_secret] = params[:secret]
|
|
62
|
-
@user = User.from_usos(params)
|
|
76
|
+
def callback
|
|
77
|
+
user = User.from_usos(session.delete(:user_data))
|
|
78
|
+
session[:current_user_id] = user.id
|
|
63
79
|
end
|
|
64
|
-
end
|
|
65
80
|
```
|
|
66
81
|
|
|
67
|
-
Here's an example for use of handle_request method in `controllers/users_controller.rb`:
|
|
82
|
+
Here's an example for use of handle_request and get_terms_grades method in `controllers/users_controller.rb`:
|
|
68
83
|
```ruby
|
|
69
84
|
class UsersController < ApplicationController
|
|
70
85
|
include UsosAuthCommon
|
|
71
|
-
def usos_auth
|
|
72
|
-
session[:access_token] = params[:token]
|
|
73
|
-
session[:access_token_secret] = params[:secret]
|
|
74
|
-
@user = User.from_usos(params)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
86
|
def grades
|
|
78
|
-
response = handle_request(session[:access_token], session[:access_token_secret], '/services/grades/terms2?term_ids=2023/24Z')
|
|
87
|
+
response = handle_request(session[:access_token], session[:access_token_secret], '/services/grades/terms2?term_ids=2023/24Z|2022/23L')
|
|
79
88
|
|
|
80
|
-
|
|
89
|
+
response_2 = get_terms_grades(session[:access_token], session[:access_token_secret], '2023/24Z|2022/23L')
|
|
81
90
|
end
|
|
82
91
|
end
|
|
83
92
|
```
|
|
84
|
-
In this example, we want to retrieve all grades from the 2023/2024Z semester.
|
|
93
|
+
In this example, we want to retrieve all grades from the 2023/2024Z and 2022/2023L semester.
|
|
85
94
|
|
|
86
95
|
## Scopes
|
|
87
96
|
When you request a Request Token, you may pass the scopes parameter, which describes the things you want the User to share with you. Many API methods require you to have the access to multiple scopes.
|
|
@@ -121,23 +130,6 @@ student_exams_write: Allows to register and unregister the student from his exam
|
|
|
121
130
|
|
|
122
131
|
Source: `https://apps.usos.edu.pl/developers/api/authorization/`
|
|
123
132
|
|
|
124
|
-
## Installation
|
|
125
|
-
Add this line to your application's Gemfile:
|
|
126
|
-
|
|
127
|
-
```ruby
|
|
128
|
-
gem "usos_auth_lib"
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
And then execute:
|
|
132
|
-
```bash
|
|
133
|
-
$ bundle
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Or install it yourself as:
|
|
137
|
-
```bash
|
|
138
|
-
$ gem install usos_auth_lib
|
|
139
|
-
```
|
|
140
|
-
|
|
141
133
|
## Contributing
|
|
142
134
|
Contribution directions go here.
|
|
143
135
|
|
|
@@ -4,33 +4,30 @@ module UsosAuthLib
|
|
|
4
4
|
authorization_url = usos_authorizer.authorize(session, request)
|
|
5
5
|
|
|
6
6
|
redirect_to authorization_url, allow_other_host: true
|
|
7
|
+
rescue StandardError => e
|
|
8
|
+
Rails.logger.error "USOS Authorize User Error: #{e.message}"
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def callback
|
|
10
12
|
verifier = params[:oauth_verifier]
|
|
11
13
|
access_token = usos_authorizer.access_token(session, verifier, nil, nil)
|
|
12
14
|
|
|
13
|
-
response = access_token.get('/services/users/user?fields=id|first_name|last_name|email
|
|
15
|
+
response = access_token.get('/services/users/user?fields=id|first_name|last_name|email')
|
|
14
16
|
parsed_response = JSON.parse(response.body)
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
session[:user_data] = parsed_response
|
|
19
|
+
session[:access_token] = access_token.token
|
|
20
|
+
session[:access_token_secret] = access_token.secret
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
url << "?id=#{parsed_response['id']}&email=#{parsed_response['email']}"
|
|
23
|
-
url << "&first_name=#{parsed_response['first_name']}&last_name=#{parsed_response['last_name']}"
|
|
24
|
-
url << "&photo_url=#{parsed_response['photo_urls']['50x50']}"
|
|
25
|
-
url << "&token=#{access_token.token}&secret=#{access_token.secret}"
|
|
26
|
-
|
|
27
|
-
redirect_to url, allow_other_host: true
|
|
22
|
+
redirect_to UsosAuthLib.configuration.redirect_path, allow_other_host: true
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
Rails.logger.error "USOS Callback Error: #{e.message}"
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
private
|
|
31
28
|
|
|
32
29
|
def usos_authorizer
|
|
33
|
-
UsosAuthLib::UsosAuthorizer.
|
|
30
|
+
UsosAuthLib::UsosAuthorizer.instance
|
|
34
31
|
end
|
|
35
32
|
end
|
|
36
33
|
end
|
|
@@ -2,17 +2,36 @@ module UsosAuthCommon
|
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
4
|
def handle_request(access_token, access_token_secret, service_path)
|
|
5
|
-
access_token =
|
|
6
|
-
|
|
7
|
-
puts access_token
|
|
5
|
+
access_token = UsosAuthLib::UsosAuthorizer.instance.access_token(session, nil, access_token, access_token_secret)
|
|
8
6
|
|
|
9
7
|
response = access_token.get(service_path)
|
|
10
8
|
JSON.parse(response.body)
|
|
9
|
+
rescue StandardError => e
|
|
10
|
+
Rails.logger.error "USOS Handle Request Error: #{e.message}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_terms_grades(access_token, access_token_secret, term_ids)
|
|
14
|
+
path = "/services/grades/terms2?term_ids=#{term_ids}"
|
|
15
|
+
handle_request(access_token, access_token_secret, path)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_course_grades(access_token, access_token_secret, course_id, term_id)
|
|
19
|
+
path = "/services/grades/course_edition2?course_id=#{course_id}&term_id=#{term_id}"
|
|
20
|
+
handle_request(access_token, access_token_secret, path)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_latest_grades(access_token, access_token_secret)
|
|
24
|
+
path = "/services/grades/latest"
|
|
25
|
+
handle_request(access_token, access_token_secret, path)
|
|
11
26
|
end
|
|
12
27
|
|
|
13
|
-
|
|
28
|
+
def get_courses(access_token, access_token_secret, course_ids)
|
|
29
|
+
path = "/services/grades/latest?course_ids=#{course_ids}"
|
|
30
|
+
handle_request(access_token, access_token_secret, path)
|
|
31
|
+
end
|
|
14
32
|
|
|
15
|
-
def
|
|
16
|
-
|
|
33
|
+
def get_user_info(access_token, access_token_secret, fields)
|
|
34
|
+
path = "/services/users/user?fields=#{fields}"
|
|
35
|
+
handle_request(access_token, access_token_secret, path)
|
|
17
36
|
end
|
|
18
37
|
end
|
data/lib/usos_auth_lib.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'usos_auth_lib/version'
|
|
2
2
|
require 'usos_auth_lib/engine'
|
|
3
3
|
require 'oauth'
|
|
4
|
+
require 'singleton'
|
|
4
5
|
|
|
5
6
|
module UsosAuthLib
|
|
6
7
|
class Configuration
|
|
@@ -25,6 +26,8 @@ module UsosAuthLib
|
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
class UsosAuthorizer
|
|
29
|
+
include Singleton
|
|
30
|
+
|
|
28
31
|
def initialize
|
|
29
32
|
config = UsosAuthLib.configuration
|
|
30
33
|
@api_key = config.api_key
|
|
@@ -43,6 +46,8 @@ module UsosAuthLib
|
|
|
43
46
|
session[:request_token_secret] = request_token.secret
|
|
44
47
|
|
|
45
48
|
request_token.authorize_url
|
|
49
|
+
rescue StandardError => e
|
|
50
|
+
Rails.logger.error "USOS Authorize Error: #{e.message}"
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
def access_token(session, verifier, access_token, access_token_secret)
|
|
@@ -64,6 +69,9 @@ module UsosAuthLib
|
|
|
64
69
|
end
|
|
65
70
|
|
|
66
71
|
token
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
Rails.logger.error "USOS Access Token Error: #{e.message}"
|
|
74
|
+
nil
|
|
67
75
|
end
|
|
68
76
|
|
|
69
77
|
private
|
|
@@ -77,6 +85,8 @@ module UsosAuthLib
|
|
|
77
85
|
authorize_path: '/services/oauth/authorize',
|
|
78
86
|
access_token_path: '/services/oauth/access_token'
|
|
79
87
|
)
|
|
88
|
+
rescue StandardError => e
|
|
89
|
+
Rails.logger.error "USOS Consumer Error: #{e.message}"
|
|
80
90
|
end
|
|
81
91
|
end
|
|
82
92
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usos_auth_lib
|
|
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
|
- mikolajczu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-02-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oauth
|