-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthentication.html
More file actions
174 lines (146 loc) · 7.64 KB
/
authentication.html
File metadata and controls
174 lines (146 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Sensorflare offers a REST API. Rest means that the URLs used are properly
describing the actions and interactions performed."/>
<title>Developer API Authentication | Sensorflare</title>
<link rel="shortcut icon" href="images/favicon.png"> </link>
<!-- CSS Stylesheets -->
<link rel="stylesheet" href="stylesheets/bootstrap.3.0.3.css">
<link rel="stylesheet" href="stylesheets/icon-font.css">
<link rel="stylesheet" href="stylesheets/icons.css">
<link rel="stylesheet" href="stylesheets/style.css">
<link rel="stylesheet" href="stylesheets/website.css">
</head>
<body>
<div id="wrap">
<!-- header-10 -->
<header id="nav" class="header-10 navbar-fixed-top">
<div class="container">
<div class="navbar col-sm-12" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle"></button>
<a class="brand" href="http://sensorflare.com"><img class="img-responsive" src="images/sensorflare-logo-website.png"
alt="Sensorflare"> </img></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav pull-left">
<li><a href="http://sensorflare.com#benefits-sec" class="web-menu-item">Benefits</a></li>
<li><a href="http://sensorflare.com#howItWorks-sec" class="web-menu-item">How It Works</a></li>
<li><a href="http://sensorflare.com#devices-sec" class="web-menu-item">Supported Devices</a></li>
<li><a href="http://blog.sensorflare.com" target="_blank" class="web-menu-item">Blog</a></li>
</ul>
<ul class="navbar-form pull-right list-inline">
<li><a href="http://sensorflare.com/user/signup.html" class="btn btn-primary btn-large navbuttons">
Get Started Free</a></li>
<li><a href="https://play.google.com/store/apps/details?id=com.sensorflare.android" id="btn-googlePlay" class="app-button">
<img src="images/sensorflare-on-google-play.png"
alt="Download it on Google Play" class="img-responsive app-button"> </a></li>
</ul>
<div class="forkme-tab">
<a id="forkme-banner" href="https://github.com/SensorFlare/rest-api">View on GitHub</a>
</div>
</div>
</div>
</div>
</header> <!--/.header-10 -->
<section id="firstSect" class="header-10-sub v-center devpage">
<div>
<div class="container">
<div class="sub-nav clearfix">
<small class="pull-left"><a href="index.html"><span class="glyphicon glyphicon-chevron-left"></span> Back to REST API</a></small>
<small class="pull-right"><a href=""></a></small>
</div>
<div class="card-wrapper">
<h3 class="devpage-header">Authentication</h3>
<h4>Protecting Private User Data</h4>
<p>
Requests that require authentication will return <code>{"status":"not found","code":404}</code> in some
cases instead of <code>{"status":"forbidden","code":403}</code>. This is to prevent the accidental
leakage of private resources to unauthorized users.
</p>
<br/>
<h4>Basic Authentication</h4>
<p> Using curl:
<pre class="terminal">$ curl -u foo:bar http://www.sensorflare.com/api/dashboard</pre>
</p>
<br/>
<p> Using Java:
<pre style="width: 100%">HttpURLConnection con = null;
try {
//Create connection
URL url = new URL("http://www.sensorflare.com/api/dashboard");
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = username + ":" + password;
String encodedAuthorization = enc.encode(userpassword.getBytes());
con.setRequestProperty("Authorization", "Basic " +
con.setRequestProperty("User-Agent", "sensorflare-java-client");
encodedAuthorization);
System.out.println("ResponseCode: " + con.getResponseMessage());
BufferedReader in =
new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con != null) {
con.disconnect();
}
}</pre>
</p>
<br/>
<h4>Authentication Errors</h4>
<p>When user authentication fails appropriate error messages are provided to the client.
<pre style="width: 100%">{
"timestamp":1398760457973,
"error":"Unauthorized",
"status":401,
"message":"Bad Credentials"
}</pre>
</p>
<br/><br/>
<div class="sub-nav clearfix">
<small class="pull-left"><a href="index.html"><span class="glyphicon glyphicon-chevron-left"></span> Back to REST API</a></small>
<small class="pull-right"><a href=""></a></small>
</div>
</div><!--/.card-wrapper-->
</div><!--/.container-->
</div>
</section>
</div><!--/.wrap -->
<!-- footer-3 -->
<footer class="footer-3" id="footer">
<div class="container text-center">
<!--<span class="menu"> <a href="#">Pricing</a> </span>-->
<!--<span class="menu"> <a href="#">About us</a> </span>-->
<span class="menu"> <a href="http://blog.sensorflare.com" target="_blank">Blog</a> </span>
<span class="menu"> <a href="#" onclick="showClassicWidget()">Contact & Support</a> </span>
<span class="menu"> <a href="https://sensorflare.github.io/rest-api/">Developers</a> </span>
<br/><br/>
<p class="brand">© 2014 Sensorflare · All rights reserved ·
<a href="http://sensorflare.com/privacy-policy.html" target="_blank">Privacy Policy</a> ·
<a href="http://sensorflare.com/terms-of-service.html" target="_blank">Terms of Service</a>
</p>
</div>
</footer>
<!-- Javascript -->
<script src="javascripts/jquery-1.11.0.min.js"></script>
<script src="javascripts/bootstrap.3.1.1.min.js"></script>
<script src="javascripts/modernizr.custom.js"></script>
<script src="javascripts/jquery.scrollTo-1.4.3.1-min.js"></script>
<script src="javascripts/startup-kit.js"></script>
<script src="javascripts/jquery.backgroundvideo.min.js"></script>
<script src="javascripts/jquery.parallax.min.js"></script>
<script src="javascripts/uservoice.js"></script>
<script src="javascripts/website.js" ></script>
</body>
</html>