Project

General

Profile

Authentification » History » Version 1

jerome bonnet, 03/14/2012 05:05 PM

1 1 jerome bonnet
h1. Authentification
2
3
h1. 1 Principles
4
5
h2. 1.1 Account
6
7
In the platform a user having family data is called an account. An account may be authenticated on the platform and has:
8
* One or several identifiers
9
* A Password: Password of a user is stored in the databased with a BCrypt Hash
10
11
h2. 1.2 Account identifiers
12
13
Each user's account on the platform is identified by one or several identifiers. Identifier properties are:
14
15
* The 'type', which is an enum that may be: 
16
> * Email: an email
17
> * Msisdn: a phone number (not used at the moment)
18
> * ExternalId: the id of an external system (for SSO integration)
19
> * Login: a login (free-form string)
20
> * AccessToken: a random string being an identifier for a cryptographic authentication token
21
> * SOMETHING_ELSE: reserved for extension mechanism.
22
23
* The 'value', which correspond to the type and must be totally unique across all users
24
25
h2. 1.3 Type of Authentication 
26
27
The server APIs falls into two different categories: 
28
29
- _*Account-based api*_ :
30
> API where the api call is relative to an account, such as wall/get (retrieve wall messages). Such apis do always work on the user's account data or on the behalf of the Account, and the account in question is not passed as an explicit argument to the api. It is an implicit argument. 
31
> Such apis mandate the caller to be authenticated and that the authentication corresponds to an account on the platform.
32
33
- _*Non-account-based api*_ , such as createAccount:
34
> API which does not consider the logged account as an implicit argument. Such apis may mandate the client (or the calling application) to be authenticated, but does not mandate that the authentication correspond to an account on the platform. For instance, the client, or an administrator, may be authenticated to perform such api calls, but they do not automatically correspond to an account.
35
36
As a result, an api call can be authenticated in two fashion:
37
38
- _*Client Authentication*_
39
> Authentication recognize the calling application and associated right to can one or another api
40
41
- _*Account Authentication*_
42
> Authentication recognize the account and therefore enable calling account-based api.
43
44
> Both authentication can be available at the same time.
45
46
For the moment, only Account Authentication is implemented, and all apis except for the "log2" api requires Account Authentication. "log2" api does not requires authentication now but will at least requires Client authentication in the future.
47
48
h2. 1.3 Client authentication
49
50
> Application are not authenticated at the moment.
51
52
> As a consequences, non-account-based apis are not authenticated, too...
53
54
*To be completed.*
55
56
h2. 1.4 HTTP Sessions
57
58
The api support (and even requires for performance reason) a session concept over HTTP.
59
60
At any time during an HTTP api call the server _MAY_ respond with an additional Set-Cookie HTTP header, setting a JSESSIONID http cookies.
61
At any subsequent call the the server, the client _MUST_ return the JSESSION id cookie, and ONLY this cookie. The cookie time-to-live on the client may be short and shall, if possible, correspond to a user session, if applicable.
62
63
At any time the server may invalidate an HTTP session and resend a JSESSIONID. However the server shall implement an HTTP session time-to-live based on a 30 minutes timeout after the lastest access.
64
65
h1. 2 Simple login/password authentication based on the http session
66
67
> This Authentication scheme will be deprecated in the future, because it does not support Client Authentication, and is poorly secure.
68
 
69
This authentication scheme consist in calling the log2in api priori to any other account-based API. Non account-based apis are left unauthenticated.
70
By calling the log2in api, the identifier/password are passed to the system and verified. The identifier must correspond to an account's identifier and the password must pass the hash test of the corresponding account.
71
72
If the authentication is successful, the current HTTP session will become Account Authenticated up to the end of the HTTP Session. 
73
74
The api log2out may be called to remove the account authentication from the current HTTP Session. This will also invalidate the current HTTP session.
75
76
Because an http session can be invalidated by the server at any time (or almost at any time, the server _SHALL_ implement a 30 minutes timeouts after the last call on a session), the client _SHALL_ be ready to manage any 501:FizAccountNotFoundInSessionException errors and redo a log2in call.
77
78
h2. 2.1 Authorization errors:
79
80
Whenever an account-based api is called without an account authentication, the following error will be returned to the caller:
81
501 :  FizAccountNotFoundInSessionException
82
83
h1. 3 OAuth2 Authentication
84
85
h2. 3.1 OAuth2 Presentation
86
87
The system is able to use various (but not all) OAuth2 authentication scenarios to provide access to account-based apis.
88
89
> Based on The OAuth 2.0 Authorization Protocol (draft-ietf-oauth-v2-23) (see http://datatracker.ietf.org/doc/draft-ietf-oauth-v2/ )
90
91
The principle is that the client must obtain an Access-Token and a Refresh-Token from the server, and then use the Access-Token to authenticate itself and use account-based apis. In order to obtain the Access-Token and the Refresh-Token, the client must use HTTPS/TLS.
92
93
The type of access-token managed by the server is "MAC Access Authentication" .
94
95
> Based on HTTP Authentication: MAC Access Authentication, draft-ietf-oauth-v2-http-mac-01 (see http://datatracker.ietf.org/doc/draft-ietf-oauth-v2-http-mac/ )
96
97
The MAC Access Token is secure enough in order to be used on plain http connection instead of HTTPS/TLS. However his time-to-live is medium-lived (ie several days). When an Access Token is obsolete, the client must use the Refresh Token to obtain a new Access Token, using HTTPS/TLS. The Refresh Token is much more long lived (several years).
98
99
The Access-Token is used by signing an http request with the token secret with a hmac algorithm and put the signature in the Authorization Header of the http request.
100
101
> Note that this authentication mechanism does not aleviate the client from handling the HTTP Sessions cookies. However the HTTP sessions will be transparently recreated and re-authenticated and the usage of the log2in api is not necessary anymore.
102
103
In order to retrieve the Access-Token or the Refresh-Token, several scenario are possible, depending on the type of application, the type of client, etc...
104
The following scenario are implemented:
105
# Oauth2 Password based authentication
106
107
*TBD: access of non-account based apis.*
108
109
*TBD: Client Authentication.*
110
111
h2. 3.2 OAuth2 error codes
112
113
When an access token is required and missing the following error is returned to the client:
114
115
<pre>
116
HTTP/1.1 401 Unauthorized
117
  WWW-Authenticate: MAC
118
</pre>
119
120
When an access token is obsolete the following error is returned to the client:
121
122
<pre>
123
HTTP/1.1 401 Unauthorized
124
  WWW-Authenticate: MAC Expired
125
</pre>
126
127
For other errors the WWW-Authenticate will provide various error messages.
128
129
h2. 3.3 Compatibility with authentication based on the http session
130
131
Normally, resource protected by OAuth will deny access of any request that do not have a valid Authorization Header.
132
However, when using the "Simple login/password authentication based on the http session" (see #2.0) concurrently, we have the following policy:
133
134
For accessing account-based apis:
135
# Any http request passed with an http session identified authentified with the "Simple login/password authentication based on the http session" will not require the OAuth 2.0 authentification
136
# Any other http request will requires the OAuth Authorization http header
137
138
For non-account-based apis, for the moment they are left unauthentified while we implement security on non-account based apis.
139
140
h2. 3.4 Fiz specific URL references
141
142
The following URL endpoint are defined:
143
144
* Token endpoint : https://<SERVER_URL/token
145
146
* 
147
148
h2. 3.5 Refresh Token usage
149
150
In order to use the refresh token, the client must present the refresh token to the /token endpoint in HTTPS/TLS.
151
See #6 of IETF OAuth specification.
152
153
Example:
154
<pre>
155
POST /token HTTP/1.1
156
  Host: server.example.com
157
  Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
158
  Content-Type: application/x-www-form-urlencoded;charset=UTF-8
159
  grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
160
</pre>
161
162
h2. 3.6 Access-Token response format
163
164
As defined in both ietf specification, the access token will be returned in JSON.
165
The only type of access-token managed is "mac". 
166
The only type of max algorithm managed is "hmac-sha-1".
167
168
<pre>
169
HTTP/1.1 200 OK
170
  Content-Type: application/json;charset=UTF-8
171
  Cache-Control: no-store
172
  Pragma: no-cache
173
  {
174
    "access_token":"2YotnFZFEjr1zCsicMWpAA",
175
    "token_type":"mac",
176
    "expires_in":3600,
177
    "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
178
	"mac_key":"AEZRDF41424aezraezr",
179
	"mac_algorithm","hmac-sha-1"
180
  }
181
</pre>
182
183
h2. 3.7 Using the MAC SHA1 access-token to generate Authorization request.
184
185
It is actually all explained here : draft-ietf-oauth-v2-http-mac-01 , but I will summarize the procedure here:
186
187
# Generate the request Timetsamp in seconds
188
# Generate a random number to be used as a nonce
189
# From the request being done, extract the HOST, PORT, HTT_METHOD, and FULL_PATH_OF_QUERY
190
# Concatenate all Timestamp, nonce, and information extracted from request into a string
191
# Compute the hmac of the concatenated string with the mac_key
192
# Generate and add an Authorization header in the http request
193
194
The format of the Authorization header is:
195
<pre>
196
 Authorization: MAC id="h480djs93hd8",
197
                     ts="1336363200",
198
                     nonce="dj83hs9s",
199
                     mac="bhCQXTVyfj5cmA9uKkPFx1zeOXM="
200
</pre>
201
202
The id is the "access_token" value, the ts is the timestamp, the nonce is (well) the nonce, and the mac is the result of the hmac computation.
203
204
h1. 4 Oauth2 Password based authentication
205
206
This type of authentication is suitable for privilegied application that take care of asking and managing the user's password.
207
It is  "Resource Owner Password Credentials Grant"
208
209
In order to retrieve an access token and a refresh token the user must call the /token endpoint in HTTPS/TLS. The username must be a valid account identifier value.
210
211
Example with a account identifier being an email:
212
<pre>
213
POST /token HTTP/1.1
214
  Host: stagingapi.familywall.com
215
  Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
216
  Content-Type: application/x-www-form-urlencoded;charset=UTF-8
217
  grant_type=password&username=johndoe@x.com&password=A3ddj3w
218
</pre>
219
220
Note: as of now, because client authentication is not supported, the Authorization header shall not be included
221
222
The typical response will be an Access-token and a Refresh-Token in JSON as defined in #3.6