0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Office365でGoogle WorkspaceをIdPにしたとき、Google側でメールアドレス変更した場合やること

Last updated at Posted at 2022-06-13

Googleでメールアドレスを変更した場合、オートプロビジョニングでOffice365上のログインアドレス(UserPrincipalName)自体は変更されるが、そのアドレスでGoogleのログインを使ってOffice365にログインしようとすると、 Message: AADSTS51004: The user account hogehoge does not exist と言われログインできない。

いろいろ掘ってみると、その理由はImmutableIdが元のままになっているからっぽい。ImmutableIdは外部IdPとの連携に使う物で、IdPのアカウント名が入っている。Auto ProvisioningでUserPrincipalNameは変更されているが、ImmutableIdは変更されないようだ。

PowershellでImmutableIdの変更をしようとすると、外部プロバイダーが設定するアカウントはSourceAnchorの設定がないやらで変更が出来ない。

Immutableidを後で変更するには以下のようなHackが必要。

Powershellで接続

事前準備

Powershellを管理権限で起動し、MSOnlineが入っていなければインストール。

 Install-Module -Name MSOnline

パーミッション云々で文句を言われたら以下を実行して権限を付ける。安全のため、このセッションでだけ権限を付与する。

Set-ExecutionPolicy RemoteSigned -Scope Process -Force

モジュールのImport

 Import-Module MSOnline

当該アドレスのImmutableidを確認

変更前のアドレスを before@hoge.com、変更後を after@hoge.com とするとき、以下のコマンドを実行し、 after@hoge.com ではなく before@hoge.com のままになっているとビンゴ。

Get-MsolUser -UserPrincipalName "after@hoge.com" | fl ImmutableId

この状態で、ImmutableIdを Set-MsolUser で変更しようとしても、 You must provide a required property: Parameter name: FederatedUser.SourceAnchor と言われて変更できない。そこで以下のような微妙なハックをする

UserPrincipalNameを書き換えてからImmutableIdを変更する。

基本GoogleをIdPにしている場合は、独自ドメインを設定していると思われる。独自ドメインでUserPrincipalNameが設定されていると、ImmubtaleIdの書き換えが出来ないようなので、一度これをOffice 365のデフォルトアドレス(@hoge.onmicrosoft.com)に変更する。

Set-MsolUserPrincipalName -UserPrincipalName "after@hoge.com" -NewUserPrincipalName "after@hoge.onmicrosoft.com"
Set-MsolUser -UserPrincipalName "after@hoge.onmicrosoft.com" -ImmutableId "after@hoge.com"

これでImmutableIdが書き換えられたので、UserPrincipalNameをもとに戻す。

Set-MsolUserPrincipalName -UserPrincipalName "after@hoge.onmicrosoft.com" -NewUserPrincipalName "after@hoge.com"

これで、Googleアカウントである after@hoge.com でOffice365にログインできるようになる。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?