- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
防止用户使用不以 @mycompany.com 结尾的电子邮件地址通过 Firebase/Google 身份验证登录我们的内部应用程序的最佳方法是什么?
package.json 依赖
"dependencies": {
"create-react-class": "^15.6.0", /* Ignore this */
"firebase": "^4.2.0",
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
"react-native-app-intro": "^1.1.5",
"react-native-google-signin": "^0.11.0",
"react-native-linear-gradient": "^2.2.0",
"react-navigation": "^1.0.0-beta.12"
}
android/settings.gradle
rootProject.name = '[My Project Name]'
include ':react-native-google-signin'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
include ':app', ':[Internal Android SDK]'
android/build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
ext {
compileSdkVersion = 26
buildToolsVersion = "26.0.1"
}
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
android/app/build.gradle
apply plugin: "com.android.application"
[...]
dependencies {
compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}
compile project(':react-native-linear-gradient')
compile project(':[Internal Android SDK]')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.facebook.react:react-native:+'
compile 'com.facebook.fresco:animated-gif:1.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
[...]
apply plugin: 'com.google.gms.google-services'
当前文件夹结构:
> app
> components [...]
> config [...]
> screens
HomeScreen.js
LoginScreen.js
[...]
> styles [...]
router.js (just a simple StackNavigator setup from react-navigation)
> assets
> fonts [...]
> img [...]
> node_modules [...]
index.android.js
index.ios.js
package.json
[...]
LoginScreen.js(这是一项正在进行的工作)
import React, { Component } from 'react';
import { Alert, Button, Image, Text, View } from 'react-native';
import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
export default class LoginScreen extends Component{
constructor(props){
super(props);
this.state = {
user: null
}
}
componentDidMount() {
this._setupGoogleSignin().then(() => console.log('Mounted & Google setup complete.'));
}
async _setupGoogleSignin() {
try {
await GoogleSignin.hasPlayServices({ autoResolve: true });
await GoogleSignin.configure({
hostedDomain: 'mycompany.com' //doesn't do anything
});
const user = await GoogleSignin.currentUserAsync();
console.log('User: ',user);
this.setState({user});
}
catch(err) {
console.log("Play services error", err.code, err.message);
}
}
_signIn() {
GoogleSignin.signIn()
.then((user) => {
console.log('User: ',user);
this.setState({user: user});
})
.catch((err) => {
console.log('WRONG SIGNIN', err);
})
.done();
}
_signOut() {
GoogleSignin.revokeAccess().then(() => GoogleSignin.signOut()).then(() => {
this.setState({user: null});
})
.done();
}
render(){
if (!this.state.user){
return (
<View style={{flex: 1}}>
<View style={{flex: 1.5, alignItems: 'center', justifyContent: 'center', marginTop: 40}}>
<Image
style={{width: 156, height: 156, resizeMode: 'contain'}}
source={require('../../assets/img/google_logo1600.png')} />
<Text style={{fontSize: 32, fontWeight: 'bold'}}>
Google Identity
</Text>
<Text style={[{fontSize: 15, paddingTop: 5}]}>
To continue, please sign-in.
</Text>
</View>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center', marginBottom: 40}}>
<GoogleSigninButton
style={{width: 312, height: 48}}
size={GoogleSigninButton.Size.Wide}
color={GoogleSigninButton.Color.Light}
onPress={() => this._signIn()}/>
</View>
</View>
);
} else {
return (
<View style={{flex: 1}}>
<View style={{flex: 1.5, alignItems: 'center', justifyContent: 'center', marginTop: 40}}>
<Image
style={{width: 156, height: 156, resizeMode: 'contain'}}
source={require('../../assets/img/google_logo1600.png')} />
<Text style={{fontSize: 32, fontWeight: 'bold'}}>
Google Identity
</Text>
<Text style={[{fontSize: 15, paddingTop: 5}]}>
To continue, please sign-in.
</Text>
</View>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center', marginBottom: 40}}>
<Button style={{width: 312, height: 48, backgroundColor: '#4385F2', color: 'white'}} title="Log Out" onPress={() => this._signOut()} />
</View>
</View>
)
}
}
}
如果有更好的方法来做到这一点,我会洗耳恭听。谢谢!
最佳答案
无法限制谁可以使用默认的 Firebase 身份验证 Google 提供程序进行身份验证。但是用户通过登录所做的所有事情都是对自己进行身份验证:“我是 Frank van Puffelen,这就是证据”。
您可以限制用户可以访问的资源。例如 Firebase Database you can use its server-side security rules以确定每个用户有权访问的内容。在这里你可以limit access to users from a specific domain .
另见:
关于android - 如何在 React Native 中限制谷歌登录到我公司的电子邮件域 (@company.com)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45739994/
这是我的本地域名 http://10.10.1.101/uxsurvey/profile/dashboard 在 Controller 中,我为用户列表设置了一个操作 redirect(control
要处理 Canonical URL,最佳做法是执行 301 重定向还是更好地为 www 和非 www 域使用相同的 IP 地址? 例如: 想要的规范 URL/域是 http://example.com
1 内网基础 内网/局域网(Local Area Network,LAN),是指在某一区域内有多台计算机互联而成的计算机组,组网范围通常在数千米以内。在局域网中,可以实现文件管理、应用软件共享、打印机
1 内网基础 内网/局域网(Local Area Network,LAN),是指在某一区域内有多台计算机互联而成的计算机组,组网范围通常在数千米以内。在局域网中,可以实现文件管理、应用软件共享、打印机
我想创建一个 weblogic 集群,其中有两个托管服务器,每个服务器在物理上独立的远程计算机上运行 根据weblogic文档 All Managed Servers in a cluster mus
我正在运行 grails 3.1.4,但在创建允许我将多个域对象绑定(bind)到其他几个域对象的模式时遇到了问题。作为我正在尝试做的一个例子: 我有三个类(class)。书籍、作者和阅读列表。 作者
我试图使用@count函数来根据它获取数据,但是在没有崩溃报告的情况下它以某种方式崩溃了。 这是代码 class PSMedia: Object { @objc dynamic var id
有谁知道是否有办法只输入字母字符而不输入数字?我想过这样的事情 CREATE DOMAIN countryDomain AS VARCHAR(100) CHECK( VALUE ??? );
我的代码: const checkoutUrl = 'https://example.com/checkout/*' window.onload = startup() function st
一些不是我编写的应用程序,也不是用 PHP 编写的,它为域 www.example.com 创建了一个 cookie。 我正在尝试替换该 cookie。所以在 PHP 中我做到了: setcookie
什么是 oauth 域?是否有任何免费的 oauth 服务?我可以将它用于 StackApps registration 吗? ?我在谷歌上搜索了很多,但找不到答案。 最佳答案 这是redirect_
自从 In October 2009, the Internet Corporation for Assigned Names and Numbers (ICANN) approved the cre
我使用 apache 作为我的应用程序 Web 服务器的代理,并希望即时更改与 sessionid cookie 关联的域名。 该cookie有一个与之关联的.company.com域,我想使用apa
我只想托管一个子域到cloudflare。我不想将主域名的域名服务器更改为他们的域名服务器。真的有可能吗? 最佳答案 是的,这是可能的,但是需要通过CloudFlare合作伙伴进行设置,或者您需要采用
When using socket in the UNIX domain, it is advisable to use path name for the directory directory m
想象两个共享一个域类的 Grails 应用程序。也许是 Book 域类。 一个应用程序被标识为数据的所有者,一个应用程序必须访问域数据。类似于亚马逊和亚马逊网络服务。 我想拥有的应用程序将使用普通的域
我有一个包含字段“URL”的表单。第一部分需要用户在文本框中填写。第二部分是预定义的,显示在文本框的右侧。 例如,用户在文本框中输入“test”。第二部分预定义为“.example.com”。因此,总
如果我要关闭并取消分配 azure 中的域 Controller ,从而生成新的 vm Generationid,我需要采取哪些步骤来恢复它? 最佳答案 what steps do I need to
我想尝试使用 Azure 作为托管提供商(我有一个域)。我读过那篇文章https://learn.microsoft.com/en-us/azure/app-service-web/web-sites
所以.... 我想知道是否有人可以在这方面协助我? 基本上,我已经创建了一个自托管的Docker容器,用作构建代理(Azure DevOps) 现在,我已经开始测试代理,并且由于我们的放置文件夹位于W
我是一名优秀的程序员,十分优秀!