Skip to content

Commit

Permalink
docs: add tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanaltun committed Sep 23, 2021
1 parent be10060 commit 506f6da
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 7 deletions.
Empty file removed tutorials/01-getting-started.md
Empty file.
41 changes: 41 additions & 0 deletions tutorials/01-http-referrers.md
@@ -0,0 +1,41 @@
# How do I restrict my App to specific websites?

Here are some examples of URLs that you can allow to set up a referrer:

- A specific URL with an exact path: www.example.com/path
- Any URL in a single domain with no subdomains, using a wildcard asterisk (_): example.com/_
- Any URL in a single subdomain, using a wildcard asterisk (_): sub.example.com/_
- Any subdomain or path URLs in a single domain, using wildcard asterisks (_): _.example.com/\*
- A URL with a non-standard port: www.example.com:8000/*

**Note:** query parameters and fragments are not currently supported; they will be ignored if you include them in an HTTP referrer.

# Example

```javascript
const express = require('express')
const restriction = require('express-restriction')
const app = express()
const port = 3000

const allowedWebsites = [
'www.foo.com/path',
'bar.com/*',
'sub.baz.com/*',
'*.qux.com/*',
'www.quux.com:8000/*'
]

// use in whole app
app.use(restriction.website(allowedWebsites))

// or use in specific routes
app.get(
'/',
restriction.website(allowedWebsites) /* only allowed websites access here */
)

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
```
Empty file removed tutorials/02-http-referrers.md
Empty file.
28 changes: 28 additions & 0 deletions tutorials/02-ip-addresses.md
@@ -0,0 +1,28 @@
# Example

```javascript
const express = require('express')
const restriction = require('express-restriction')
const app = express()
const port = 3000

const allowedIpAddresses = [
'192.168.0.1',
'172.16.0.0/12',
'2001:db8::1',
'2001:db8::/64'
]

// use in whole app
app.use(restriction.ip(allowedIpAddresses))

// or use in specific routes
app.get(
'/',
restriction.ip(allowedIpAddresses) /* only allowed ip addresses access here */
)

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
```
60 changes: 60 additions & 0 deletions tutorials/03-android-apps.md
@@ -0,0 +1,60 @@
# How do I restrict my APP to specific Android applications?

You can restrict APP to specific Android applications by providing a debug certificate fingerprint or a release certificate fingerprint.

## Debug certificate fingerprint

For Linux or macOS:

```sh
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
```

For Windows:

```sh
keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
```

## Release certificate fingerprint

```sh
keytool -list -v -keystore your_keystore_name -alias your_alias_name
```

> Replace your_keystore_name with the fully-qualified path and name of the keystore, including the .keystore extension. Replace your_alias_name with the alias that you assigned to the certificate when you created it.
# Example

```javascript
const express = require('express')
const restriction = require('express-restriction')
const app = express()
const port = 3000

const allowedAndroidApps = [
{
packageName: 'com.foo',
signature: 'd30dac129121e16967719b6291afa16675445d75'
},
{
packageName: 'com.bar',
signature: '1591082628a39381544ba0c30e707c382ecae1dc'
}
]

// use in whole app
app.use(restriction.android(allowedAndroidApps))

// or use in specific routes
app.get(
'/',
restriction.android(
allowedAndroidApps
) /* only allowed android apps access here */
)

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
```
Empty file removed tutorials/03-ip-addresses.md
Empty file.
Empty file removed tutorials/04-android-apps.md
Empty file.
23 changes: 23 additions & 0 deletions tutorials/04-ios-apps.md
@@ -0,0 +1,23 @@
# Example

```javascript
const express = require('express')
const restriction = require('express-restriction')
const app = express()
const port = 3000

const bundleIdentifiers = ['com.foo', 'com.bar']

// use in whole app
app.use(restriction.ios(bundleIdentifiers))

// or use in specific routes
app.get(
'/',
restriction.ios(bundleIdentifiers) /* only allowed ios apps access here */
)

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
```
Empty file removed tutorials/05-ios-apps.md
Empty file.
11 changes: 4 additions & 7 deletions tutorials/tutorials.json
@@ -1,17 +1,14 @@
{
"01-getting-started": {
"title": "Getting Started"
},
"02-http-referrers": {
"01-http-referrers": {
"title": "HTTP Referrers"
},
"03-ip-addresses": {
"02-ip-addresses": {
"title": "IP Addresses"
},
"04-android-apps": {
"03-android-apps": {
"title": "Android Apps"
},
"05-ios-apps": {
"04-ios-apps": {
"title": "iOS Apps"
}
}

0 comments on commit 506f6da

Please sign in to comment.