Azure AD B2C中对React React Native应用的授权

时间:2019-10-28 13:35:40

标签: azure react-native azure-active-directory react-native-android azure-ad-b2c

有人成功在 Azure Ad B2C中创建具有授权的本地应用程序吗?

我为React Web应用程序和.Net Core API做到了,但是,我为React Native找到的任何库都无法正常运行,而且我是React Native的初学者。请给我一些提示教程或回购。我被卡住了。

1 个答案:

答案 0 :(得分:0)

我找到了适用于Azure AD B2C的React-Native库。您可以关注this article。 这是示例:

import B2CAuthentication from "../auth-ad-js/ReactNativeADB2C";
import LoginView from "../auth-ad-js/LoginView";

const CLIENT_ID = "<provide your client id>";

export default class LoginScreen extends React.Component {
  static navigationOptions = {
    title: "Login"
  };

  render() {
    const b2cLogin = new B2CAuthentication({
      tenant: 'yourtenant.onmicrosoft.com',
      client_id: CLIENT_ID,
      client_secret: "<key set in application/key>",
      user_flow_policy: "B2C_1_signupsignin",
      reset_password_policy: 'B2C_1_password_reset',
      token_uri: "https://saroujetmp.b2clogin.com/saroujetmp.onmicrosoft.com/oauth2/v2.0/token",
      authority_host: "https://saroujetmp.b2clogin.com/saroujetmp.onmicrosoft.com/oauth2/v2.0/authorize",
      redirect_uri: "https://functionapp120190131041619.azurewebsites.net/.auth/login/aad/callback",
      prompt: "login",
      scope: ["https://saroujetmp.onmicrosoft.com/api/offline_access", "offline_access"]
    });

    return (
      <LoginView
        context={b2cLogin}
        onSuccess={this.onLoginSuccess.bind(this)}
      />
    );
  }
  onLoginSuccess(credentials) {
    console.log("onLoginSuccess");
    console.log(credentials);
    // use credentials.access_token..
  }
}