├── example ├── .watchmanconfig ├── .gitignore ├── .DS_Store ├── .buckconfig ├── package.json ├── index.ios.js ├── index.android.js └── .flowconfig ├── .flowconfig ├── src ├── const.js ├── index.js ├── logger.js ├── types.js ├── ADLoginView.js ├── README.md └── ReactNativeAD.js ├── package.json └── README.md /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | android/ 3 | ios/ 4 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [options] 8 | -------------------------------------------------------------------------------- /example/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wkh237/react-native-azure-ad/HEAD/example/.DS_Store -------------------------------------------------------------------------------- /example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /src/const.js: -------------------------------------------------------------------------------- 1 | export default { 2 | 3 | GRANT_TYPE : { 4 | AUTHORIZATION_CODE : 'authorization_code', 5 | REFRESH_TOKEN : 'refresh_token' 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import ADLoginView from './ADLoginView' 2 | import ReactNativeAD from './ReactNativeAD' 3 | import Logger from './logger.js' 4 | 5 | export { 6 | ADLoginView, ReactNativeAD, Logger 7 | } 8 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RNAzureAD", 3 | "version": "0.1.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start" 7 | }, 8 | "dependencies": { 9 | "react": "^0.14.8", 10 | "react-native": "^0.24.1", 11 | "react-native-azure-ad" : "^0.1.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-azure-ad", 3 | "version": "0.2.5", 4 | "description": "A Azure AD authentication library implementation uses pure react native API (no native library needed).", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "azure", 11 | "azureAD", 12 | "active directory", 13 | "react-native", 14 | "oauth" 15 | ], 16 | "dependencies": { 17 | "react-native-webview": "^5.12.1" 18 | }, 19 | "repository": { 20 | "url": "https://github.com/wkh237/react-native-azure-ad.git" 21 | }, 22 | "author": "wkh237", 23 | "license": "MIT", 24 | "dependencies": { 25 | "react-timer-mixin": "^0.13.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/logger.js: -------------------------------------------------------------------------------- 1 | const levels = { 2 | ERROR : 4, 3 | WARN : 3, 4 | INFO : 2, 5 | DEBUG : 1, 6 | VERBOSE : 0, 7 | } 8 | let level = 4 9 | 10 | export default { 11 | 12 | /** 13 | * Set log level, this value should be a string 14 | * ERROR, WARN, INFO, DEBUG 15 | * @param {[type]} val [description] 16 | * @return {[type]} [description] 17 | */ 18 | setLevel: (val:string) => { 19 | console.log('log level set to ', val) 20 | level = levels[val] 21 | }, 22 | 23 | verbose: (...args) => { 24 | if(level <= 0) 25 | console.log('VERBOSE:', ...args) 26 | }, 27 | 28 | debug: (...args) => { 29 | if(level <= 1) 30 | console.log('DEBUG:', ...args) 31 | }, 32 | 33 | info: (...args) => { 34 | if(level <= 2) 35 | console.log('INFO:', ...args) 36 | }, 37 | 38 | warn: (...args) => { 39 | if(level <= 3) 40 | console.warn('WARN:', ...args) 41 | }, 42 | 43 | error: (...args) => { 44 | if(level <= 4) 45 | console.error('ERROR:', ...args) 46 | }, 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/types.js: -------------------------------------------------------------------------------- 1 | //@flow 2 | 3 | export type ADConfig = { 4 | client_secret : string | null, 5 | client_id : string | null, 6 | redirect_uri : string | null, 7 | tenant : string | null, 8 | prompt : string | null, 9 | resources : Array | null, 10 | token_uri: string | null 11 | login_hint : string | null, 12 | }; 13 | 14 | export type ADCredentials = { 15 | [key:string] : ReactNativeADCredential | null 16 | } 17 | 18 | export type GrantTokenResp = { 19 | resource : string, 20 | response : Object 21 | }; 22 | 23 | export type ReactNativeADConfig = { 24 | client_id : string, 25 | redirect_uri? : string, 26 | authority_host : string, 27 | tenant : string, 28 | client_secret : string, 29 | resources : any, 30 | onSuccess : Function, 31 | }; 32 | 33 | export type ReactNativeADCredential = { 34 | access_token : string, 35 | expires_in : number, 36 | expires_on : number, 37 | id_token : string, 38 | not_before : number, 39 | pwd_exp : string, 40 | pwd_url : string, 41 | refresh_token : string, 42 | resource : string, 43 | scope : string, 44 | token_type : 'Bearer' 45 | }; 46 | -------------------------------------------------------------------------------- /example/index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { 8 | AppRegistry, 9 | Component, 10 | StyleSheet, 11 | Text, 12 | View 13 | } from 'react-native'; 14 | 15 | import {ReactNativeAD, ADLoginView, Logger} from 'react-native-azure-ad' 16 | 17 | Logger.setLevel('VERBOSE') 18 | 19 | const config = { 20 | client_id : 'client-id-of-your-app', 21 | // redirectUrl : 'http://localhost:8080(optional)', 22 | // authorityHost : 'https://login.microsoftonline.com//oauth2/authorize(optional)', 23 | // tenant : 'common(optional)', 24 | // client_secret : 'client-secret-of-your-app(optional)', 25 | resources : [ 26 | 'https://graph.microsoft.com', 27 | 'https://outlook.office.com', 28 | 'https://outlook.office365.com', 29 | 'https://wiadvancetechnology.sharepoint.com', 30 | 'https://graph.windows.net', 31 | ] 32 | } 33 | 34 | class RNAzureAD extends Component { 35 | 36 | 37 | constructor(props) { 38 | super(props) 39 | new ReactNativeAD(config) 40 | } 41 | 42 | render() { 43 | return ( 44 | 45 | 50 |